More in depth [1] and in the yellow paper linked in the stack exchange question.
[1] http://ethereum.stackexchange.com/questions/52/how-were-gas-...