Food scientists previously used the bomb calorimeter to figure out how many calories are in a meal. Accordingly, they put the food in a sealed container, submerge it in water, and then burn the food inside the container while measuring the change in water temperature, because a calorie is defined as the amount of energy it takes to heat up a kilogram of water one degree Celsius.
Today, we take a few short cuts: Most of the nutritional information you find on food labels is generated indirectly, using what's known as the Atwater system. Calories are calculated by adding up the calories provided by each of the food's energy-containing nutrients, such as proteins, fats, carbohydrates and alcohol.
According to the Atwater system, there are on average four calories in each gram of protein, nine in each gram of fat, seven in each gram of alcohol, and four in each gram of carbohydrates. Because some carbs contain fiber that your body can't break down, their total is adjusted accordingly before figuring out calories.
Atwater already figured all that out using the bomb calorimeter, so now we don't have to.
"How Do Food Manufacturers Calculate the Calorie Count of Manufactured Foods?" (Scientific American)