Though moths and butterflies are familiar, popular, and extraordinarily successful—there are more than 160,000 species—the details of their origin story have been murky. Researchers have tried to decipher those details by comparing the physical features of living and fossilized moths. But it’s “extremely difficult to estimate” how fast such features evolve, says Adriana Briscoe from the University of California, Irvine, and this approach tends to underestimate the timing of important evolutionary events—such as the origin of ears.

To get better answers, Kawahara and his team spent years traveling around the world’s nighttime forests and luring moths with ultraviolet lamps. By comparing the genes of 186 species, they created a family tree that shows how different groups are related and, crucially, when the major milestones in their evolutionary history occurred.

The closest living relatives of moths and butterflies are caddis flies, insects that spend their larval lives in the water before changing shape and taking to the air. About 300 million years ago, insects with a similar lifestyle left the water to feed on early land plants, such as mosses, liverworts, and ferns. Larvae lived inside plants, devouring them from within and eventually emerging as winged adults that flew from leaf to leaf. These were the first moths.

These creatures would probably not have spawned a dynasty of 160,000 species without two important innovations. First, about 241 million years ago, the munching jaws of the adults transformed into a coiled straw—a proboscis. This allowed them to sip the nectar of flowering plants, which were then relative newcomers, only starting their long ascendance. Second, some of the caterpillars stopped mining the interiors of plants and began feasting on the surface, eating them from outside in.

With more room, they grew bigger bodies that measured in inches rather than millimeters. The larger caterpillars could walk about to find more nutritious leaves, other host plants, or places to pupate in safety. Bigger caterpillars produced bigger adults, which could fly greater distances in search of food. This likely cemented their relationship with flowering plants. “They pollinated the flowers, the plants became diverse, and the moths became diverse in synchrony,” Kawahara says. His family tree shows that the two groups radiate in synchrony—another classic evolutionary story and one that, mercifully, “appears to be correct,” he says.

Flying high on flower power, moths thrived, but mostly by night. But about 98 million years ago, some of them became active in the day, and gave rise to the butterflies—a group that Barber wryly describes as “an uninteresting diurnal group of moths.” Here again, bats have been implicated. In 1999, Jayne Yack of Carleton University proposed that echolocating bats were such a threat that some moths escaped by fleeing the night entirely, shifting to daylight hours. “The butterfly, in effect, was therefore ‘invented’ by the bat,” she wrote.