The calorie figure on a package looks like a measurement taken from that food. It is almost always a calculation, built from a small set of average conversion factors applied to the composition.
The original measurement was combustion
Food energy was first quantified by burning a sample inside a sealed chamber surrounded by water and recording the temperature rise.
This gives the total chemical energy the sample contains, which is not the same as the energy a body can obtain from it.
Some material passes through undigested, and some absorbed material is excreted rather than fully oxidised, so raw combustion overstates what is available.
Average factors replaced direct measurement
Corrections for digestion and excretion were folded into a set of general factors: broadly four calories per gram for protein and carbohydrate, nine for fat and seven for alcohol.
Manufacturers determine how much of each macronutrient a product contains and multiply by these factors. No burning is involved in routine labelling.
The factors are population averages derived from mixed diets, so they are approximations applied uniformly to foods that differ considerably.
Food structure changes what is extractable
Energy availability depends on physical form as well as chemistry. Intact cell walls in whole nuts or seeds shield some fat from digestive enzymes, and part of it leaves in stool.
Grinding, cooking and processing break those structures down and make more of the same material accessible.
Two foods with identical composition on paper can therefore deliver different amounts of usable energy, and the label cannot show that.
Digestion has its own energy cost
Absorbing, transporting and processing nutrients consumes energy, an effect called the thermic effect of food.
The cost is not uniform across macronutrients: protein carries a markedly higher processing cost than fat or carbohydrate.
Label figures do not subtract this cost, so the net energy from a protein-heavy food is lower than its stated value relative to a fat-heavy one.
Fibre and tolerances add further slack
Fibre reaching the colon is partly fermented by gut bacteria into compounds the body can use, so it is not energy-free, and jurisdictions handle it differently in the calculation.
Labelling rules also permit a tolerance between stated and actual content, since batches vary.
The number is a reasonable estimate for comparing products, and a poor instrument for precise arithmetic about an individual's intake.