How is this number 21 million bitcoins arrived at? What is the mathematics behind this number? Or is this number a constant that can be changed in the source code?
every detail of bitcoin can be changed by the developer by editing the source code. 21million was satoshi nakamotos design decision. afaik this number is not directly contained in the source-code. every ~10minutes a new block will be created. every 210000 (~every 4 years) blocks will the block reward be halved. so in many years (after many halvings) miner will not anymore really earn blockrewards because the blockrewards are approximately 0btc. => then virtually no new bitcoins will be created. that is why the entire amount of bitcoin is limited. (but the miner still earn the transaction-fees).