Question: Estimates have been thrown around a lot recently as to the year in which the last Bitcoin will be mined- where are these estimates coming from? Could someone send me to the relevant code?

Answer: 
Bitcoin's reward schedule is implemented in eras of 210,000 blocks. The block subsidy gets halved with the first block of each new era. The 33rd "halving" at block 6,930,000 will reduce the block subsidy limit from 1 satoshi per block to 0 satoshi per block¹ and therefore the last block creating new bitcoins will be block 6,929,999.

At block intervals of 10 minutes, 210,000 blocks translate to about 3.99 years, although blocks have been found faster in average in the past. Under the simplifying assumption that the halvings will occur about every four years, the final block that creates new bitcoins would occur approximately in **2140**.

You can find a table with the respective calculations here: [Bitcoin Reward Schedule](https://docs.google.com/spreadsheets/d/12tR_9WrY0Hj4AQLoJYj9EDBzfA38XIVLQSOOOVePNm0/pubhtml?gid=0&single=true)

Really, the mining reward will get minuscule much earlier already. In 2036 99% of the bitcoins will be in circulation, in 2048 it will be 99.9%.

---

¹Actually, the limit is 0.58207661 satoshi per block at that point, but since only whole satoshis can be paid out, none may be collected by miners.
As per considering mining of any cryptocurrency is calculated by increasing hash rate and difficulty and decreasing block rewards. So time prediction of final block mining is 2145.