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: 
The estimate is **2140** based on the block reward halving frequency of four years. [According to math and knowledge that there are 32 halving events](https://bitcoin.stackexchange.com/questions/8823/how-many-bitcoin-are-mined-per-day), in 2136, the block reward will yield 0.00000168 BTC per day, which is 0.00000042 BTC per block. That's 42 [satoshis](https://bitcoin.stackexchange.com/questions/114/what-is-a-satoshi). 

It's arguable that there could be one additional halving, to a block reward of 0.00000021 BTC, but that would require a major protocol modification since the number of Bitcoin would then exceed 21 million. Additionally, to go past that, there'd have to be a protocol modification to extend divisibility past eight decimal places. It is far, far to early to worry about either of these, because we're more than a century away from this problem.
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.