This is a topic that obviously stirs many passions in people and has been discussed and debated extensively. I would refer you to the following examination of the language in the second amendment. http://www.constitution.org/2ll/schol/2amd_grammar.htm
A quick summary of that exchange is that the second amendment does not grant any rights (just as we saw with the first amendment) but assumes them to be inherent to existence and that a well regulated militia is one of the purposes of having an armed citizenry but is not the only reason for it.
The text of the Second Amendment reads "A well regulated Militia, being necessary to the security of a Free State, the right of the people to keep and bear Arms, shall not be infringed."
As you have probably heard before people point to the well regulated statement and say that it is the only reason for people to ever have firearms but that is exactly the opposite of how a militia works. Militias are groups citizens who are not part of the regular army that are called to fight and they may be armed by the state but at least with the American revolutionary war many brought their own weapons because of a lack of government weaponry. So it would make no sense for the next part of the amendment to focus specifically on the right of the PEOPLE to keep and bear arms if it was only meant for military service.
Let’s take a quick look at the definition of the word Arms, Merriam-Webster defines it as "A means (as a weapon) of offense or defense" and the Oxford English Dictionary defines it as "Weapons and ammunition." Lastly from thelawdictionary.org we get "the arms of a militiaman or soldier, and the word is used in its military sense." From this it is a safe conclusion that the Constitution expressly codifies the right of the people to keep and bear MILITARY weapons and that this right should never be infringed.
This amendment like the First amendment is directed at the federal government and it is telling them that they cannot infringe upon the rights of citizens to keep and bear arms. Additionally the only way you would not be legitimate in bearing arms is if you were to use them in a way that abridges another’s right such as their right to security of person. This of course does not include using them for defense against any number of attackers. Once they have begun to make an attempt to prevent you from being secure in your person or property they have put the right to their own personal security right out the window whether the attacker is an individual or a government is irrelevant to your right to be secure.