The Fortress Guard
The Fortress Guard is a military organization that essentially serves as a combined police and militia. Dwarves can be inducted into the Guard when the sheriff is promoted to the captain of the guard.
The game interface suggests 1/10 (rounded down) of the fortress population should be members of the fortress guard. Ignoring this requirement mostly just annoys nobles, and the captain of the guard will have to deal with justice matters on his own. Once the hammerer arrives, he will personally deal out his own brand of justice.
Guards act like military dwarves, but they cannot be commanded. They will attack any hostile creatures they see, but usually ignore wild animals. When not patrolling the fortress, they will engage in sparring or target practice the same way regular soldiers with the same assigned weapon will. In a siege, the fortress guard tend to make suicidal charges at the enemy and get slaughtered.
To assign a dwarf to the Fortress Guard,iew the dwarf, select references, and you will see a new option Fortress Guard. This option only appears after the Sheriff is promoted to Captain of the Guard.
Dwarves in the Fortress Guard spend most of their time sparring and will gain weapon (or wrestling) skill very quickly. Unfortunately, once they reach "Great" skill with their weapons, they will become heroes and can no longer be turned back into regular soldiers or civilians, greatly reducing their flexibility. If you want to retain use of dwarves in the Guard, either switch their weapons when they get above Adept, or rotate them into the regular military, where you can still give them orders. See Soldier#Heroes and Champions for more details.
 The Royal Guard
The Royal Guard is activated by the arrival of any civ leader noble. For most forts this will be the Baron, but could be the Count, Duke or King if you jump a couple of steps up the social ladder at once. Dwarves are assigned to the Royal Guard in the same manner as the Fortress Guard (from the iew -> references menu), and act in most respects like the Fortress Guards do. They are mainly involved in the collection of taxes, but they will also spar in the barracks and can be assigned weapons and armor.
Nobles such as the Baron and consorts will receive unhappy thoughts if there are not enough Royal Guards. You need 1/20 of your population, rounded down, in the Royal Guard to avoid this.