The origin of air as we know it begins with the Oxygen Catastrophe, also known as the Great Oxidation, which occurred about 2.7 billion years ago. Prior to this, the level of oxygen in the air was approximately 1/50th of a percent. This is similar to the level of oxygen present in the atmosphere of Mars, about 1/5th of a percent. Like modern-day Mars, the atmosphere of early Earth was primarily carbon dioxide. Today, the atmosphere contains 20% oxygen, and only 0.038% carbon dioxide, making the air thoroughly breathable for oxygen-dependent organisms such as ourselves.
With the advent of oxyphotosynthesis in microorganisms, this carbon dioxide was progressively consumed, creating the "waste product" of elemental oxygen. The Oxygen Catastrophe is clearly demarcated in the geological record by the introduction of large amounts of oxygenated iron (rust). These relics are called banded iron formations. The event is called a "catastrophe" because oxygen is toxic to anaerobic organisms, which the event wiped out in large numbers. There was a time lag of about 300 million years before the evolution of the first oxygen-producing organisms and the full-fledged Oxygen Catastrophe.
In the subsequent billions of years, oxyphotosynthesizing organisms flourished, producing more and more elemental oxygen. The history of air, from practically zero oxygen to 20% oxygen, stretches over more than two billion years. During the Carboniferous period, approximately 250 million years ago, when plants thrived, oxygen levels were even higher than they are today. This permitted the existence of very large insects, including a dragonfly, Meganeura, with a two-foot wingspan. Today's air would be unbreathable to Meganeura, due to its relative lack of oxygen.
The search is ongoing for extraterrestrial planets with air similar to that of Earth, with no luck thus far. By examining the spectrum of a planetary body closely, astronomers can determine its chemical composition, even if that body is extremely distant. This is the same technique used to determine the chemical makeup of far-away stars.