The earth is estimated to be about 4.5 billion years old.
The age of the earth is based primarily on calculations of the half life of Uranium.. the half life of Uranium is about 4.5 billion years. There are samples of Uranium that are half lead the daughter element and half Uranium. This indicates that one half life of the Uranium has passed. One Half life of Uranium would be 4.5 billion years.
These calculations are based on the assumption that the original pieces of Uranium was 100% Uranium and that no lead was present when the mineral was formed. It also assumes that no Uranium has been lost due to erosion in the 4.5 billion years that the mineral is thought to have existed.
Both of the assumptions of 100% Uranium and no erosion are of course subject to error but the calculations based on these assumptions gives an estimated age of the earth of 4.5 billion years.
The solar system started as a nebula, or cloud of space gas. Gravity caused the atoms of this gas to coalesces into a core. The remaining material orbited around that core as a big gaseous disk. The inner most gas fell to the core and that is how the sun was formed.
Additional cores were formed over millions of years and around each of these cores new disks of gaseous material and other elements formed. Eventually these fell into the cores and we ended up with planets. The act of fusion, caused by gravity, is what turned a lot of gas and loose heavier atoms, into the iron core the Earth has today.