It’s not like the government just sends a pile of unknown generic soldiers into battle. The military has records of all the personnel under its command, and all of the soldiers have their own records stored somewhere, along with their families and property, and so it’s not a complicated matter to discover who came back and who didn’t. The individual military units also know who’s under their command and how things progressed, what kind of casualties they’ve suffered, and that information will be reported back through their chain of command in order to resupply the unit.
Modern day: every injury, death, etc. has to be counted with its own case. These cases are updated as the status of the patient / remains changes, either through treatment or travel. These are counted within the system to give these numbers.
Source : I worked with this system while I was stationed in Landstuhl, Germany. Where almost all injuries and fatalities from down range travel through to get back to the states.
Depending on the era and how chaotic the situation was, you started by asking each team, platoons and companies to do a head count. You will get the immediate known KIA numbers and a lot of MIA. Most platoons and companies can keep track how many are left and how many known deaths.
Early armies would stop at this point and simply hand out the pay up to the reported amount to the paymaster and let him do the counting. If they don’t pay, it goes into rations and food distribution team to calculate how many men are left vs how much food left.
Then you track down the MIA in the hospitals, infirmaries, morgues, dump sites.
That will give you the bulk of your data.
What’s left are the guys going AWOL, mixed in bodies with the civilians, simply don’t have a body, captured by enemy, lost somewhere, or send somewhere else before…etc.
Latest Answers