The planet is generally thought of as having three distinct atmospheres over the course of its lifetime.
When earth was first formed, its atmosphere was likely composed of hydrogen, helium, and other gases that contained hydrogen. Yet this atmosphere didn't last for very long because the solar wind from the sun blew it away. Solar wind is stream of charged particles such as electrons, protons, and alpha particles. We now have a magnetic field surrounding earth that shields us from solar wind.
The second atmosphere formed a little after 4.5 million years ago (mya) and was produced due to volcanic outgassing. Outgassing is the release of gas that was trapped in some other material. In this case, volcanic outgassing released hot gases trapped deep within the interior of the planet. Water vapor, carbon dioxide, methane, ammonia, and other gases similar to the ones produced by volcanoes today were expelled.
Over a vast amount of time, millions of years, the earth gradually cooled. When the temperature dropped enough, water vapor condensed and went from a gas to liquid form. This created clouds. From these clouds, the oceans formed and the oceans absorbed a lot of the carbon dioxide in the atmosphere. A small amount of oxygen was produced by the photolysis of carbon dioxide and water vapor by ultraviolet radiation.
Lastly, we have the third atmosphere. Around 2.5 mya, the amount of oxygen available in the atmosphere started to rise due to the evolution of photosynthetic organisms that produced oxygen. These organisms were oceanic cyanobacteria. Over time, aerobic organisms evolved and consumed some of the oxygen produced. Read more about how oxygen became a major part of our atmosphere here.
This is the composition of the atmosphere we have today: