About 100 years ago an agricultural chemist by the name of Wilbur O. Atwate was one of the first persons to workout calories in food. As mention before in another article , calorie is define as a unit of energy. What Wilbur articulated was that the amount of calories contained within a certain food is determined by the amount of energy it gives off if you burn it! Nutritionally speaking, 1 calorie is defined as 1,000 times the energy it takes to heat a gram of water from 14.5 to 15.5 degrees Celsius. (Hope we all understand that little science fact).
Companies have developed modernized methods of testing the calorie component and the other nutritional attributes of food. They are required to work out calories in food by the FDA for various reasons but most of all, health reasons.
Hope I was able to shed some light on how they work out calories in food.