Oddbean new post about | logout
 We all know there's only 21 million bitcoin, right? Well actually, it's 20,999,999.9769 minus 50 from the genesis block. To understand why we need to look at the relevant function:
https://m.primal.net/IbBO.png
This is often written in mathematical notation as:
https://m.primal.net/IbBU.png 
But this actually produces the value 20,999,999.99755528 (which is 2,065,528 sats more than the correct value).

So why the discrepancy? Well, it has to do with the right bitwise shift operator which has only 8 decimals of precision supported. At the 11th halving cycle (10 when zero indexed) we start to see different results:
https://m.primal.net/IbCH.png 

Now you're prepared for your next bar quiz.

Fun fact: the if statement in the code was not there originally so after 64 halving cycles the block subsidy would have reset to 50. Check out BIP42 for more details.