[Homeostasis] was the driving question that led James Lovelock and Lynn Margulis in the early 1970's to formulate the famous and endlessly debated Gaia Hypothesis, in which the two argued that "early after life began, it acquired control of the planetary environment and that this homeostasis by and for the biosphere has persisted ever since."
Lovelock and Margulis [published a paper on Gaia describing] oxygen's miraculous stability. They gave the paper a provocative title "Atmosphere Homeostasis By and For the Biosphere." By and For: these were fighting prepositions. Not only had the planet achieved some kind of sustained atmospheric balancing act, with oxygen levels maintained at optimal levels for its present biosphere, but that biosphere had somehow collectively been responsible for it, acting in its own self interest... It was a variation on Sir John Pringles's "no vegetable grows in vain" homily, with mankind replaced by Mother Earth. The biosphere regulates O2 levels, and it does it for a reason: because stable O2 levels are good for the biosphere.
One of the intriguing side effects of Gaia is that it helped trigger a multidisciplinary search to determine if oxygen leves had indeed been consistently locked in at 21 percent over the ages... By measuring the levels of carbon and sulfur in sedimentary rocks for each geological period --- drawn largely from the extensive data compiled by oil companies seeking new deposits of fuel --- [Robert] Berner and [Donald] Canfield were able to build a portrait of atmospheric oxygen dating back 600 million years... The data showed a dramatic spike in oxygen levels, reaching as high as 35 percent around 30 million B.C., followed by a plunge to the borderline asphyxia of 15 percent in the Triassic era, 100 million years later.
Plants absorb carbon dioxide and produce oxygen through photosynthesis; decomposition plays the tape backward, as bacteria and other animals use up oxygen breaking down the plant debris, releasing carbon dioxide in the process.
-excerpt from The Invention of Air by Steven Johnson