And how, you may reasonably wonder, can scientists know what oxygen levels were like hundreds of millions of years ago? The answer lies in a slightly obscure but ingenious field known as isotope geochemistry. The long-ago seas of the Carboniferous and Devonian swarmed with tiny plankton that wrapped themselves inside tiny protective shells. Then, as now, the plankton created their shells by drawing oxygen from the atmosphere and combining it with other elements (carbon especially) to form durable compounds such as calcium carbonate. It's the same chemical trick that goes on in (and is discussed elsewhere in relation to) the long-term carbon cycle—a process that doesn't make for terribly exciting narrative but is vital for creating a livable planet.
Eventually in this process all the tiny organisms die and drift to the bottom of the sea, where they are slowly compressed into limestone. Among the tiny atomic structures the plankton take to the grave with them are two very stable isotopes—oxygen-16 and oxygen-18. (If you have forgotten what an isotope is, it doesn't matter, though for the record it's an atom with an abnormal number of neutrons.) This is where the geochemists come in, for the isotopes accumulate at different rates depending on how much oxygen or carbon dioxide is in the atmosphere at the time of their creation. By comparing these ancient ratios, the geochemists can cunningly read conditions in the ancient world—oxygen levels, air and ocean temperatures, the extent and timing of ice ages, and much else.