The Earth formed about 4.6 billion years ago. Nobody was there to measure the air, so scientists build up a picture from evidence such as ancient rocks and the gases that volcanoes release today. The early atmosphere is thought to have come from volcanic activity. Volcanoes released mostly carbon dioxide, together with water vapour, a little nitrogen and small amounts of methane and ammonia. There was little or no oxygen.
As the Earth cooled, water vapour condensed to form the oceans. Carbon dioxide dissolved in the oceans, and some of it became locked away in sediments and carbonate rocks such as limestone. Carbon was also locked away in fossil fuels. This is why the level of carbon dioxide fell. Nitrogen is unreactive, so it was not removed and slowly built up.
Today the air is about 78% nitrogen and 21% oxygen, with about 1% argon and only about 0.04% carbon dioxide. The evidence is billions of years old and limited, so the theory is uncertain and ideas change when new evidence is found.