Once upon a time, perhaps some 300 million years ago, a tiny stream-dwelling insect akin to a caddis fly crawled from the water and began to live on mosses and other land plants. Although drab in appearance, the creature had a glorious future: It would become the ancestor of the 160,000 species of moths and butterflies that populate Earth today.

Few insect fossils have been found, so reconstructing the steps in this long evolution has been difficult. A group of biologists has now filled some of the major gaps in the fossil record, with the help of data from the DNA and protein sequences of living insects. On Monday the team, led by Akito Y. Kawahara of the Florida Museum of Natural History in Gainesville, published a paper in Proceedings of the National Academy of Sciences that rewrites key aspects of the narrative of how moths and butterflies evolved.

A central part of this story is the furious evolutionary battle between moths and bats. Bats hunt moths by emitting pulses of sound. But moths gradually adapted, developing the capacity to detect the pulses and respond with evasive flight maneuvers. The bats adapted in turn, and new species arose that used sonar frequencies that the moths could not hear as well. New moths arose in response, equipped with countermeasures: They could broadcast sounds that either jammed the bat’s sonar, probably by throwing off the estimate of the moths’ distance, or advertised that the moth’s tissues were poisonous.