The Earth is about 4.6 billion years old, and no one was there to record the first atmosphere. Scientists work out what it was like from indirect evidence, such as the chemistry of ancient rocks and the gases given off by volcanoes today. This means the ideas are theories that fit the evidence, and there is still some uncertainty about them.
It is thought that intense volcanic activity released the gases that formed the early atmosphere. The main gas was carbon dioxide, with water vapour and nitrogen, and small amounts of methane and ammonia. There was little or no oxygen.
As the Earth cooled, the water vapour condensed and fell as rain to form the oceans. Carbon dioxide dissolved in the oceans, and some of it ended up locked away in sediments such as limestone and in fossil fuels. Nitrogen is unreactive, so it built up. This is why the amount of carbon dioxide fell and nitrogen became the most common gas.
Today the atmosphere is about 78% nitrogen, 21% oxygen and about 0.04% carbon dioxide, with small amounts of other gases such as argon and water vapour.