This measurement method assumes that all calories in a food become available to the body during digestion. One study on almonds and human digestion, however, challenges this assumption by showing how much of the nuts were, shall we say, excreted before they were fully digested.
Another component of digestion that isn't usually measured in the calories-in, calories-out equation is how much energy is expended while breaking down a food. For instance, it is theorized that protein requires a lot of heat energy to process, and therefore the net caloric intake can be lower than for other types of macronutrients. With this consideration in mind, researchers at Harvard University theorized that the more a food is processed before it is eaten, the more calories will be available without energy lost to digestion.
To test this theory, they studied the effects of two kinds of food processing on the diets of lab mice. Mice were fed whole raw organic sweet potatoes or organic whole raw lean beef, or those same foods processed by either pounding, cooking or both. The mice were monitored for movement, and care was taken to account for food scraps and "outputs." At the end of the study, the mice fed cooked food gained weight, and the mice fed raw food lost weight (the mice fed pounded food gained slightly less weight.) Another study supports this hypothesis: it found that people expended more energy digesting whole-grain bread and natural cheese sandwiches than highly-processed white bread and cheese food.
The article mentions other attributes to digestion that can make caloric availability vary from situation to situation; physiology, digestive flora, and genetic predispositions play a role in how well food is digested - but one important point remains: if you eat food that is highly-processed, you will take in more calories.