The original atmosphere that surrounded Earth 4.5 billion years ago is thought to have been composed of hydrogen and helium, since these were the two elements that made up the Sun. However, being very light gases, they would have gradually escaped from the Earth's gravitational pull and passed into outer space, only to be replaced by other gases.
Hydrogen and helium were gradually replaced by a second atmosphere as more and more gases were released by volcanoes. This second atmosphere probably consisted of a mixture of gases, and would have included carbon dioxide, methane, ammonia, hydrochloric acid and sulfur dioxide. There would have been little, if any, oxygen present. Scientists believe it is unlikely that the large amount of water present on Earth could have been caused by volcanism. Far more likely is the assumption that it was imported onto Earth by collisions with asteroids, some of which are comprised of mostly ice.
The effect of sunlight on volcanic gases in the then atmosphere was to break up the ammonia into gaseous nitrogen and hydrogen. Some of the latter would have combined with free oxygen to form water vapor. Nitrogen continued to build up gradually, and it is now 78 percent of the atmosphere.
Bacteria started to evolve on Earth approximately 3.3 billion years ago, and this was to change the atmosphere gradually into the one that we are familiar with today. Between 2.2. and 2.7 billion years ago, these bacteria used the Sun's energy through photosynthesis, the first organisms on Earth to do so, taking in carbon dioxide and giving up oxygen during the process. These bacteria are called cyanobacteria. Over the eons, the effect of this has been to increase the Earth's atmosphere's proportion of oxygen to about 20 percent, its present value.