Every x blocks the mining reward is halved. Will the reward be halved forever such that we never quite reach 21 million bitcoins, or will we reach 21 million bitcoins at some point and will the reward cease to exist altogether?

The 11th 210000 blocks each allow creating 0.04882812 BTC, and not 0.048828125 BTC, because only 8 decimals of precision are supported.

...

The 33rd 210000 blocks each allow creating 0.00000001 BTC.

After that, the reward is 0.

If you sum all these numbers together, you get 20999999.9769 BTC.

... however, either due to an oversight or intentionally, the coins created in the genesis block cannot be spent.

This leaves us with 20999949.9769 BTC.

... however, due to an early problem in Bitcoin, fixed by BIP30, it was possible to create a coinbase transaction identical to a previous coinbase. This caused the coins created by that older coinbase to be irreversibly "overwritten". This happened in block 91842 (overwriting the coinbase of block 91812) and 91880 (overwriting the coinbase of block 91722). Each time, 50 BTC was lost.

This leaves us with 20999849.9769 BTC.

... however, the protocol rules allow creating up to the amounts listed above. Due to various bugs and miners experimenting with code, some blocks claim less than allowed. Those coins can never be recovered.

Block 124724 tried to intentionally claim 0.00000001 BTC less than allowed, but accidentally also failed to claim the fees, losing 0.01000001 BTC.

Between block 162705 and block 169899, 193 blocks claimed less than allowed due to a bug, resulting in a total loss of 9.66184623 BTC.

Between block 180324 and block 249185, another 836 blocks claimed less than allowed, resulting in a total loss of 0.52584193 BTC.

... however, since recently there is a concept of provably unspendable coins. Coins can be sent to an "address" which provably burns them (using OP_RETURN). Bitcoin Core tracks these and removes them from its database, so they are easily accounted for. At least 3.71612692 BTC were burned this way.

This leaves us with 20999817.31308491 BTC (taking everything up to block 528333 into account)

... However, various wallets have been lost or stolen, transactions have been sent to the wrong address, people forgot they owned bitcoin. The totals of this may well be millions. People have tried to tally known losses up here.

Arturo: no. You can just create a transaction with a higher fee though, if you want to give money to miners.
– Pieter WuilleAug 7 '15 at 13:09

2

Arturo: to clarify, typically an OP_RETURN output would have value 0, so it won't burn anything. It still increases the transaction size, so it increases the necessary fee for relay and mining.
– Pieter WuilleAug 7 '15 at 19:23

Note that it cuts the reward in half using the bit-shift operator, which means that eventually it won't be able to reduce the block reward by exactly half. So how many Bitcoins does it end up making in total?

20,999,999.9769 BTC, or 2,310,000 satoshis short of 21 million. (If you want to be a lot of fun at parties, bring this up whenever someone says that the maximum number of Bitcoins is 21 million.)

Then there are the various Bitcoins that aren't spendable due to various quirks of the Bitcoin protocol, like the genesis block coinbase, or the duplicated coinbase. [Edit: Or the many other instances of unspendable Bitcoins that Pieter mentions in his answer.]

Upvoting, as my own answer does not actually link to the code!
– Pieter WuilleAug 7 '15 at 0:26

3

Note that the right-shift operator's behavior isn't defined for shifts of 64 or more bits. So block 13,440,000 will set 'halvings' to 64, and most compilers currently treat ">> 64" the same as ">> 0", so the reward goes back to 50 BTC per block after 64 halvings (in around 2272). Except that this bug was already fixed, hard-coding the reward to be 0 after 63 halvings.
– Chris MooreJul 8 '16 at 1:08

20997107.88801356 once you remove the 2709.42507135 BTC “burn addresses” i.e. the bitcoin addresses with almost assuredly no earthly known private keys and therefore unspent lost forever. There are ~400 burn addresses with a total balance of 2759.42507135 as of Dec 2017 (2709.42507135 excluding the genesis block). Last year the burn addresses balance grew by 8.97 BTC