How did oxygen come to make up 21 percent of earth's atmosphere?

Answer

When life first came about 3.5 billion years ago, there most likely was no oxygen in the atmosphere. This fact is indicated by iron in rocks formed during that time: in an oxygen environment, Fe2+ oxygenates to Fe3+, or rust. During that time, there was no evidence for rust.

Plants evolved out of a "primordial soup", a mixture of elements and some form of energy like light, geothermal heat, etc. Experiments have shown that, given the chemicals that we know to have been around during that time (CO2, H2O, NH3, H2, etc.), the basic units for life were produced. This includes amino acids, carbohydrates, fatty acids, and nucleobases.

The first plants formed from this primordial soup are thought to be the ancestors of green and purple algae. With the evolution of plants, CO2 fixation began and O2 evolution occurred. Thus, over several billion years, oxygen began to build up as plants grew in number and diversified.

Currently, nitrogen takes up about 78% of the air we breath, oxygen takes up 21%, and a variety of other chemicals like water and CO2 represent the remaining 1%. Our bodies don't need 100% oxygen; in fact, oxygen can be toxic in large doses.