The first question is waht is a Calorie anyway?
A Calorie is a unit that is a measure of energy, kj or Kilojoules are also used and there is a way to convert Calories to Kilojoules below. The 'Calorie' with think about when we talk about food is actually an abreviation of Kilocalorie (kcal). In otherwords when we say something has 10 Calories we should actually be saying 10,000 Calories. But humans love abbreviations, and it's stuck.
The precise definition of a kcal is "the amount of energy needed to raise the temperature of 1 kilogram of water 1 degree Celsius".
Originally the way the calorie value of foods was measured was to burn it in a sealed container (called a bomb calorimeter) that was immersed in water, and the temperature change measured to figure how much energy was released. One problem with this method is that you could burn cardboard in the calorimeter and measure the energy released, but that won't tell how much energy you get from eating cardboard.
The United States National Data Lab (NDL), states that "most of the calorie values in the USDA and industry food tables are based on an indirect calorie estimation"
The system used is Atwater system. In this system calories are not measured by burning the foods. Instead the total calorific value is calculated by totaling the each of the energy-containing nutrients: protein, carbohydrate, fat and alcohol. Adjustments are also made to recognise that some components are completely digested because humans can't breakdown complex molecules like cellulose (think sweetcorn, peanuts, cardboard).
The Atwater system uses the average values of 4 Kcal/g for protein, 4 Kcal/g for carbohydrate, and 9 Kcal/g for fat. Alcohol is calculated at 7 Kcal/g. (These numbers were originally determined by burning and then averaging.) Thus the label on an energy bar that contains 10 g of protein, 20 g of carbohydrate and 9 g of fat would read 201 kcals or Calories.
There is further information at these websites:
This was adapted from an article in The Scientific American