It all happened in just an evolutionary moment. Sixty-six million years ago, a huge asteroid burned its way into Earth's atmosphere and annihilated the non-avian dinosaurs. The survivors – mammals, frogs, reptiles and more – spread out, diversified, and became many of the species we know today.

But new research has zeroed in on what snakes were doing during this time, called the Cretaceous-Paleogene (K-Pg) mass extinction. It now appears that just a handful of asteroid-surviving snakes went on to evolve into all of today's serpentine species.

"It's remarkable, because not only are they surviving an extinction that wipes out so many other animals, but within a few million years they are innovating, using their habitats in new ways," says first author and phylogeneticist Catherine Klein, who undertook the work while at the University of Bath.

There's been a bit of scientific back-and-forth about how much squamates – reptiles such as lizards and snakes – were affected by the mass extinction.

Originally, it was thought they suffered minimal losses, but in North America particularly there was evidence of a high rate of squamate extinctions at the K-Pg border.

"The evolutionary history of snakes across the K-Pg boundary has been particularly difficult to assess," the team writes in their new paper.

A lack of early snake fossils has meant evolutionary genetic analysis of snakes relies on a very restricted set of characteristics. This can result in biased patterns that may not reflect their true genetic history, the team explains.

But by combining different modelling approaches involving genetic data and fossil sampling in different time periods, the researchers have provided a comprehensive view of modern snakes from then to now.

So, the asteroid landed, the dinosaurs fell, and there was suddenly a lot more room to move. How did the snakes fare?

The extinction of competitors (including other snake species) meant the survivors could slither about to their heart's content and move into new niches, new habitats, and even new continents.

"Our research suggests that extinction acted as a form of 'creative destruction' – by wiping out old species, it allowed survivors to exploit the gaps in the ecosystem, experimenting with new lifestyles and habitats," said one of the team, University of Bath evolutionary researcher Nick Longrich.

"This seems to be a general feature of evolution – it's the periods immediately after major extinctions where we see evolution at its most wildly experimental and innovative. The destruction of biodiversity makes room for new things to emerge and colonize new landmasses. Ultimately life becomes even more diverse than before."

There were cretaceous snakes before this period – we know this because their vertebrae were different back then. But, when those snakes mostly died off, modern snakes in all of their wonderful shapes and forms started to emerge after the destruction. Vipers and cobras, tree and sea snakes, boas and pythons – they all occurred after the massive 10 kilometer (6.2 miles) asteroid decimated Earth.

"The Cretaceous-Paleogene (K-Pg) mass extinction caused the demise of numerous vertebrate groups, and its aftermath saw the rapid diversification of surviving mammals, birds, frogs, and teleost fishes," the team writes.

"Our results help corroborate the fundamental role of the K-Pg mass extinction in shaping the vertebrate biodiversity occupying our planet today."

Well, life really does find a way.

The study has been published in Nature Communications.