They don’t. Rather, they give you an average per mass that is derived from testing. Testing could be mass spectrometer, burning the food and recording the temperature change, etc. Carbs and Proteins have 4 kilocalories per gram and fat has 9 kilocalories per gram.
Latest Answers