First, a sample is logged into the system. Contract labs are certified by various bodies, and accurate records are a vital part of that.
Then the sample will be blended [Homogenised is the fancy word]. This is literal, a big food processor is used, and usually around a kilo of whatever sample is sent in. Sometimes a lot more, I've blended everything from bin bags full of popcorn to whole turkeys.
Some of the sample is saved in a deep freezer, some is saved in a fridge. From the fridge sample, smaller samples are taken for each test.
Protein is calculated by burning it in a furnace to measure the nitrogen content. From the nitrogen content you can calculate the protein present in the sample.
Moisture is measured by drying the sample overnight. Weighing it before and after lets you calculate the amount of the sample that was water.
With the dried sample, you can perform a crude fat measurement using NMR. This is much faster and easier than other fat analyses, but it only gives you an idea of fat content, not what kinds of fat are present. NMR is the same sort of technology that is used in MRI machines, but in this case is tuned just to measure hydrogen atoms in a liquid state.
A drop of fat or oil is extracted from a sample and then used in a machine called a Gas Chromatograph. The droplet is vapourised at around 400 degrees centigrade and sent through a glass fiber tube. Big fat molecules in the droplet go slower than small ones, and so by detecting them as they come out of the tube, you know what order and amount of each one there was in the fat. From this you can calculate how much saturated and unsaturated fat is present, as well as more details like Omega 3 & 6 content.
Sugar content is analysed in a similar manner, but with a Liquid Chromatograph.
Fiber is measured by dissolving a sample in different solvents, different enzyme baths, until only the fiber is left, it is then dried and weighed. If Carbohydrate calculation is needed, the sample is paused halfway for a drying and weighing stage
With this set of information; Fats, Proteins, Carbohydrates, Sugars, Fiber and Moisture, the calorie content of food can be calculated.
Other things are also analyzed, but that's the usual bare minimum for nutritional information. Most contract labs offer them as a "suite" of tests.
I hope that's about the right level for a 5 year old. Usually when I talk science to kids they can interrupt me to ask questions and I can explain what a molecule, or what have you, is.