Let me start like this, hair colour is determined by a particular chemical called melanin. Now every strand of hair stems from a hair follicle and every hair follicle contains a certain amount of pigment cells and these pigment cells are what produce melanin.
Now the thing is, the older we get the weaker our bodies become and thus the pigment cells begin to weaken as well and die. As the pigment cells start dying, the amount of melanin produced begins to reduce and as a result, the hair begins to lose its colour.
Due to the lack of melanin, the hair begins to turn gray or white and eventually just about all your hair will become like that. It's a natural process and cannot be avoided.
Thanks for the answer! I was always wondering about that. It's great to finally find out about what is causing it.
You're welcome @runicar, glad I could help.