earth was formed 4.5 billion years ago volcanoes released hydrogen,methane,carbon dioxide and water vapor was also released into the atmosphere.There was little oxygen at the time.
for the first couple billion years,earth experienced a lot of volcanic activity.Earth also began to cool down,due to this the water vapor began to form earths oceans.The water began to dissolve gases such as ammonia away from the atmosphere, this created ammonia compounds and other nitrogen containing compounds that are suitable for life.
as plants and algae began to evolve in the oceans carbon dioxide rates dropped due to the plants photosynthesizing, they acted a carbon sink, an ozone layer was beginning to form.
animals began to evolve and they exhaled carbon dioxide however carbon dioxide still stayed low due to the formation of sedimentary rocks like limestone
now the atmosphere is 78% nitrogen,21% oxygen and less than 1% carbon dioxide
however carbon dioxide percentages are rising due to burning fossil fuel,livestock and de-forestation and other factors caused by humans green house gases are being produced at an alarming and dangerous rate.