Could someone explain me how the total quantity of bitcoin is limited to 21 millions?
Please, don't tell me it is written in the program

It is. The way mining works is that the miners will mine blocks with the correct block reward and that is the way that Bitcoins are distributed. The block reward is coded into the clients and they will only accept blocks with the correct block reward and that is how they have a limited supply.
However, its not perfect and it is impossible for it to be exactly 21 million Bitcoins. Even if it can be, the earlier miners had poorly written client that resulted in incorrect block rewards being claimed and thus the exact value is far from 21million Bitcoins.