Our estimate of the age of the Earth comes from analysing the amounts of radioactive elements in rocks. A radioactive element decays into another stable element (called a ‘daughter element’) at a predictable rate. Some decays are very rapid but others are slow, taking over a billion years for half of the radioactive atoms to change. If we measure the amounts of one of these slowly-decaying radioactive elements and the amounts of its daughters in a piece of rock then we can estimate how old the rock is. The answer is about 4.5 billion years.
Our estimate of the age of the Sun comes from analysing its size, mass, and luminosity (i.e. brightness). We then apply our understanding of what powers stars and find an estimate of around 4.7 billion years old.
Our estimate of the age of the Universe comes from analysing the motion of stars and galaxies. As we look at objects further and further away we are looking at objects as they were when the light was emitted. We can see objects from which light has taken about 13 billion years to reach us, and we think these objects were formed less than a billion years after the ‘big bang’.