It's really pretty simple. Each State in the new Republic had an army (Militia, which in the English of the day was defined as: "The army, in its entirety." Barclay's English Dictionary, London, ca 1820).
The Federal Government needed some standing army, large enough to settle disputes between States should they come to conflict, intervene in the event one State invaded another, or to repel foreign invasions of any or all of the several states.
However, the Founders rightfully were concerned about the ability of such an army to overcome the Civil Authority, and impose tyranny--something of which the colonial military governorships of the prior years left fresh memories.
Hence, that army had to be regulated (controlled, as regulators and regulations do).
That end was to be achieved by the people (all of them) having the Right to keep and bear their personal arms, which, in extremis, even without the benefit of martial training and by sheer numbers would be able to act as a deterrent to military dictatorship, and if necessary, defeat such aims by force.
This discussion is laid out in the Federalist Papers.
Thus, "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."
Pretty plain to me.
Three worst decisions of the last 100 years? Miller, Roe, and The ACA