It is no magic, in the simplest explanation it all comes down to the law of thermodynamics and calorie balance.
If you are interested in this kind of stuff, check Lyle's website[1]. He has many good articles about this kind of stuff.
[1]: http://www.bodyrecomposition.com/fat-loss/the-energy-balance...