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.
Is it the Militia that can carry guns or the individual people? In the 1700's, the Militia was all able bodied males. In British common law, everyone was responsible for using force to enforce the King's Peace. That was the world in which the Founding Fathers lived. To the framers, there was no difference between "militia' and citizen.
Did the Virginia National Guard fight off the Redcoats? No, of course not. A gang of guys with guns in their houses gathered themselves up to go fight. Were they putting down bandits? Again, no. They were putting down the King's Army. The second amendment was regarded explicitly (George Mason, Patrick Henry, and in state constitutional debates) as a guarantee against a standing army of the, then as yet to be, United States of America. The second amendment protects the right of individuals to own weapons so they can go blast the army if need be.
There was quite a bit of debate between the Federalists and the Anti-Federalists on this point. The Anti-Federalist didn't want to sign the Constitution, in part, because they feared a national army. They figured the army could be used to abuse them, and that wars could be fought on a voluntary basis. The Federalists wanted the Constitution to signed.
They hit upon a compromise. The Anti-Federalists would sign, so long as there rights were forever enshrined in the Bill of Rights, including the second amendment.
As a reminder, the second amendment includes the word 'regulated', which doesn't mean the bureaucracy we have now. It mean that the individual must be trained and responsible with the weapon. Conducting your affairs in such a manner that a child is not safe with a weapon is not a protected right.