Passages in the book give some details on how the Terran Federation originated:
At the end of 20th century, national governments of the world collapsed due to the failure of "unlimited democracies", civil unrest and social workers and child psychologists, a "pre-scientific pseudo-professional class", banning corporal punishment, resulting in crime reaching endemic proportions.
Illegal activity which took place all around the world, including in Russia and in the United Kingdom, brought down the North American Republic. In 1987, the resulting Russo-Anglo-American alliance became engaged in a war with the Chinese Hegemony. Shortly before the war's end, the "Revolt of the Scientists" tried to create a utopia through a coup d'état but soon failed. The war ended in 2130 with the humiliating Treaty of New Delhi, which made large concessions to the Hegemony. This treaty freed prisoners captured by the Russo-Anglo-American Alliance, but left 65,000 civilians (Japanese, Filipino and Russian) and two divisions of British Paratroopers (sentenced for political crimes) in Chinese incarceration, leaving them escape as the only way to freedom. The loss of the war (or rather, a negotiated peace on extremely unfavorable terms, somewhat like the Treaty of Versailles that ended World War I) left the West and Russia on the brink of anarchy.
After the collapse of national governments, a group of veterans in Aberdeen, Scotland, formed a vigilante group to stop rioting and looting. They hanged a few people (including two veterans) and decided to only allow veterans to join their committee due to a mistrust of politicians. This contingency plan became routine after a couple of generations, and this group of vigilantes originated the Terran Federation. It is expressly stated that this was never intended to be a coup d'état and was more comparable to the Russian Revolution: one system collapsed on its own and another rose to fill its place.
The Terran Federation has a multicultural society that votes for a global leader, similar to a representative democracy. However people of higher levels of authority also have to suffer tougher repercussions of their actions: e.g. a lieutenant could hang for making a mistake that a private would merely be dismissed and maybe lashed for. Corporal and capital punishment are practiced by the government as well as spanking children being standard use amongst the population.
A "History and Moral philosophy" instructor in the Army says "personal freedom for all is [the] greatest in history, laws are few, taxes are low, living standards are as high as productivity permits, crime is at its lowest ebb."
The people of the Terran Federation are either "Citizens" or "Civilians". Everyone is born a "Civilian", and at age 18 every "Civilian" has the right to enroll for a minimal 2-year term of "Federal Service". After completing a term of Federal Service "Civilians" become "Citizens" and gain the right to vote.
In theory a completed term of Federal Service ensures a "Citizen" is willing to put the needs of the community before their own personal well-being. This is because Federal Service is tough and dangerous (by design). It can involve joining the military, being a human guinea pig, testing survival equipment, or manual labour. The Federation makes it quite easy to quit a term of service before completion (even during war-time), but once someone has quit they are never allowed to enroll again. This is to ensure that all volunteers are dedicated, whilst also discouraging people from leaving.
The Federation makes the opportunity of Federal Service open to everyone, able-bodied or not. A doctor giving a medical examination says "if you came in here in a wheelchair and blind in both eyes and were silly enough to insist on enrolling, they would find you something silly to match. Counting the fuzz on a caterpillar by touch, maybe." The only impediment that can render one ineligible for federal service is if a psychiatrist determines that one cannot understand the oath of service.
"Civilians" are neither discriminated against, nor deprived of legal rights other than that of the ballot. Several examples from the book bear this out, particularly the fact that Juan Rico's family is prosperous and lacks for nothing save the right to vote (which Rico's father regards as "useless" anyway).
The Terran Federation's military appears to be divided into an Army and a Navy (that uses spacecraft instead of ships and doubles as an air force). The dozens of non-combat and support branches include units for logistics, biological/chemical weapons development, and terraforming. The "Sky Marshal" commands the entire military. To be eligible for the post of Sky Marshal, an officer must reach certain high ranks in both the Army and the Navy.
Once in the military a volunteer has the choice to "go career", choosing to devote 20 years of service to the Federation instead of the usual two years required to gain Citizenship. After these 20 years they can then leave and get a "reserved job", for example in the police. If they quit before then, after choosing the career path, the Federation is less supportive to them in the Civilian world. A minimal 2-year service can be extended if the Federation deems it necessary, as explicitly stated in the "Service Oath" taken upon enrollment.
Distinctive military units include:the "Mobile Infantry" (Army). They use "Powered Armor Suits" (and are featured largely in the book). These suits are very versatile and combine the powers of tanks and paratroopers making earlier battlefield units obsolete.
the "K9 Corps" act as reconnaissance units using "Neodogs" via an emotional bond with them. A Neodog, an "artificially mutated symbiote derived from dog stock", can speak and has the average intelligence of a child aged 8 – 12 years.
clairvoyants and psychics
engineers who do not use powered suits; Rico describes them as valiant fighters even though they are unskilled.
The Navy has powerful weapons capable of destroying planets (e.g. "Nova Bombs"). A majority of ship-board ranks are filled by females. The primary role of the Navy involves providing transportation for infantry forces.
Heinlein suggests that "revolution is impossible" in the Terran Federation: stability ensues from arming aggressive types as "sheepdogs" while "the sheep will never give you any trouble". According to Franklin, "[t]he underlying premise of the new social order is that the only people fit to govern the state are those willing to sacrifice their lives for the state".
Donald M. Hassler and Clyde Wilcox describe the Terran Federation as "Heinlein's last attempt to articulate a perfect government" and as "the ultimate embrace of both military and democratic ideas within a single state. This fantasy utopia lends itself to a historical comparison of the positive effects of the military on liberty and personal freedom. Such a comparison will also highlight the inherent potential threat to liberty the military poses simply by its existence. If, in this idealized state militarism can be recognized as an ever present menace, then, a fortiori, the danger it represents is even more critical for existing democracies. Broadly drawn, the Terran Federation is a liberal, representative democracy."
Stephen E. Andrews and Nick Rennison note that the "Terran Federation, which Heinlein clearly expects us to admire, is said by his most extreme detractors to be analogous to Nazi Germany."
In the film adaptation, the United Citizen Federation (UCF) was used in place of the Terran Federation and has many of the hallmarks of a fascist government, including heavy-handed propaganda, the demonization of an external foe, the centralized organization of society for total war, military (or militarized) and not civilian leadership, and omnipresent uniforms.
The formation of the UCF is not fully explained in the movie. However, dialogue at the beginning of the film suggests its formation was similar to the Terran Federation (albeit more bloody).
In order to vote in the UCF (and its novel counterpart), one must provide "Federal Service" by serving in the military or other service. The social structure of the world is divided between citizens (people who have served) and civilians (people who haven't served).