Irked by irritating insects? Be glad you didn’t live in the late Carboniferous period.

Three hundred million years ago, jumbo bugs zipped along with 2-foot-wide wingspans — nearly the size of a crow’s. Now, scientists think they know the secrets to their super size: Sky-high oxygen levels and no hungry birds.

The enormous insect Meganeura or griffinfly reigned in the late Paleozoic era — about 70 million years before dinosaurs tromped around. Now extinct, their fossils reveal a bug resembling current-day dragonflies.

“They’re related to dragonflies; they’re sort of like their uncles,” said paleobiologist Matthew Clapham of UC Santa Cruz.

The mega bugs, whose fossils have been found in France and Kansas, were thought to swoop over lush swamps and inland seas, chomping on smaller critters while dodging the era’s tall palmlike trees and ferns.

Clapham’s research team at UC Santa Cruz has been trying to solve the mystery of how they managed to grow so monstrous — though oxygen levels have long been suspected. The study was published Monday in the Proceedings of the National Academy of Sciences.

Insects don’t breathe with lungs, but rather through a series of oxygen-absorbing pipes that traverse their bodies. With higher oxygen levels in the air, it is easier for insects to breathe. Moreover, with better oxygen supplies, scientists hypothesize that they could sustain bigger bodies.

“When you grow insects in a box with lots of oxygen, they get bigger,” Calpham said.

In the late Carboniferous period, when griffinflies hit their peak size, scientists calculate that the atmospheric oxygen levels also peaked at 30 to 35 percent compared to today’s 21 percent.

To test whether there’s a relationship or just a coincidence, the team assembled more than 10,000 fossil records of flying insects through the past 300 million years.

Fossils of bug bodies are hard to come by, Clapham said.

They’re either eaten by predators or decomposed by microbes, but wings keep well. So, the team used wingspan as a proxy for body size.

When they compared wingspan records to the known oxygen levels, they found a clear correlation.

Between 300 million and 150 million years ago, when oxygen went up, so did maximum insect wingspan. With drops in oxygen levels, insect wings got shorter.

That is, until birds evolved.

About 150 million years ago, birds like the famous Archaeopteryx entered the scene. The hawk-size early birds looked much like dinosaurs with feathers and long tails, Clapham said, and they hunted the enormous flies and other insects.

With new predators, quick maneuverability would be useful to thwart attacks.

The fossil records indicate the wingspan dropped to a more agile size, half the length of the Carboniferous period’s griffinflies, despite rises in the oxygen levels.

It’s a possible theory, said animal flight scientist Robert Dudley from UC Berkeley.

“They haven’t proven that it’s body size, per se,” Dudley said. There’s a strong correlation between wing length and body size, but it’s not perfect, Dudley said.