The Earth formed around 4600 million years ago, when a hot, dense mass of gas and dust around the sun collapsed on itself - this was caused by gravity.

A mass of gas and dust got hotter and hotter as the particles were pulled in and squashed together. It then began to cool down, solidify and break up into chunks called planets - one of which was Earth.

Around 4500 million years ago, the hot gases that had built up inside the Earth burst out through volcanoes. Gradually, over millions of years our atmosphere developed from these gases.

As molten rock poured out of the Earth's crust it threw out water vapour, carbon dioxide, nitrogen, hydrogen chloride, hydrogen (so light it went straight into outer space!), and smaller amounts of argon and other noble gases.

The water vapour cooled and condensed and formed the oceans.

This is where life on Earth began 3500 million years ago.

All the hydrogen chloride and much of the carbon dioxide dissolved in rain and ocean water. This acidic solution attacked rock and wore it away.

The first green plants appeared about 2200 million years ago - this is when photosynthesis began. It used up carbon dioxide and produced oxygen.

Some of the oxygen reacted with other elements; the rest went into the atmosphere!

The ozone layer

The ozone layer is about 25 km above sea level, in the stratosphere. It has the formula O3. It is produced when ultra-violet light causes oxygen molecules to break into atoms.