All things must pass. That includes life on Earth, which will surely be wiped out eventually. But how long does it have?

The fossil record tells us that life on Earth has lasted at least 3.5 billion years. In that time it has survived being frozen, clobbered by rocks from space, mass poisoning, and even lethal radiation. Clearly, it's hard to completely sterilise the planet.

But there's no shortage of potential apocalypses. Which of them will finally render the Earth barren?

Volcanic apocalypse

Timeframe: 0-100 million years? Maybe?

Probably the nearest life has come to ultimate destruction was 250 million years ago, during the end-Permian mass extinction. The event obliterated perhaps 85% of all species living on land - and 95% of all ocean-dwelling species.

Lava smothered an area eight times the size of the UK

No one is quite sure what happened, but it seems to be no coincidence that the extinction coincided with volcanic activity on a truly apocalyptic scale. Today we worry about the destructive power of supervolcanoes like Yellowstone. But the damage they might bring is nothing compared to what happened 250 million years ago.

Back then, Siberia experienced such a large and sustained period of activity that lava smothered an area eight times the size of the UK. Volcanic activity on that scale is rare, but not unheard of.

No one knows when the next such episode will happen, says Henrik Svensen at the University of Oslo in Norway. Similar-sized eruptions happened 200, 180 and 65 million years ago, so they're not terribly regular. But one will surely happen eventually, and when it does the key question will be where it goes off.

Svensen's research suggests that a mega-eruption's ability to wipe out species will depend on exactly where it punches through Earth's crust. That's because the volcanic activity 250 million years ago might not have been directly responsible for the massive extinction. The killer ingredient might have been salt.

It's unlikely that life itself would disappear

Siberia is rich in salt deposits. When they were baked by the volcanic activity, Svensen thinks they released vast quantities of ozone-destroying chemicals into the atmosphere. Species all over the world then had to cope with harmful radiation from space that atmospheric ozone normally soaks up. The stress might well have killed most of them.

The bad news is that there are plenty of massive salt deposits on Earth today. "East Siberia is still among the largest reservoirs," says Svensen. "Offshore Brazil is also big."

If a mega-eruption formed in one of these areas, many species would die. But it's unlikely that life itself would disappear. After all, while plants and animals fared poorly during the end-Permian extinction, single-celled organisms like bacteria sailed through virtually unharmed.

Asteroid threat

Timeframe: within 450 million years, maybe?

It's common knowledge these days that asteroids and dinosaurs don't get along. If a massive asteroid could contribute to the extinction of all of the world's large dinosaurs, could one also wipe out all life on Earth?

Again, that might depend on exactly where the rock lands. We know that the Earth has been hit by some very large asteroids that have barely registered as life destroyers.

Impacts on the scale of the dinosaur killer are rare

The Manicouagan crater in Canada - one of the largest impact craters on the planet - was created in a destructive impact about 215 million years ago. But the fossil record shows it didn't trigger a dinosaur-scale extinction. That might be because the crater formed in relatively inert crystalline rock. Craters that form in volatile-rich sedimentary rocks, in contrast, might send clouds of climate-changing gases into the atmosphere, triggering global mass extinctions.

The good news is that impacts on the scale of the dinosaur killer are rare. Such big rocks may only strike Earth once every 500 million years.

But even if one does come along, mass extinction is unlikely to become mass sterilisation. That would probably only be possible if Earth was hit by something even bigger than an asteroid: a rogue planet.

There might be a precedent for that. Some scientists think Earth was clobbered by a rogue planet soon after it formed, and that the resulting cloud of debris formed the Moon. "We can call this the Melancholia hypothesis, after Lars Von Trier's movie," says Svensen. Still, this possibility seems pretty remote.

When the core freezes over

Timeframe: 3 to 4 billion years

While we're on the subject of movies, consider 2003's The Core. The story is that Earth's core has mysteriously stopped rotating, so the US government backs a plan to drill to the centre of the Earth and restart it – because without an active core, Earth loses its magnetic field and all life is threatened.

Mars once had, and then lost, a magnetic field

The Core is mostly nonsense and has been rightly derided by scientists. But not all of the science it features is junk. Some researchers really do think that Earth's magnetic field deflects ionising particles from the sun, which would otherwise wear away Earth's atmosphere. If they are right, then without a magnetic field our planet will lose its atmosphere too, and all life will die.

Something like this may have happened on Mars, which may once have been more hospitable to life than it is now.

In 1997, Joseph Kirschvink at the California Institute of Technology in Pasadena and his colleagues found good evidence that Mars once had, and then lost, a magnetic field. "The Martian magnetosphere collapsed sometime after 3.7 billion years ago, which is about the time that the planet went into a permanent snowball state," says Kirschvink.

You may have heard that Earth's magnetic field is weakening. But don't worry: that's because the magnetic field is in the process of flipping direction, not dying. These flips have happened periodically for millions of years.

Could Earth's magnetic field eventually disappear?

"If the field reverses, this doesn't mean that it dies out completely," says Richard Holme at the University of Liverpool in the UK. The flip might well do odd things to the magnetic field but "wouldn't greatly disrupt life", he says.

Could Earth's magnetic field eventually disappear? Not any time soon, says Richard Harrison at the University of Cambridge in the UK.

For that to happen the core would have to completely solidify. Currently only the inner core is solid, while the outer core is liquid. "[The inner core] grows about a millimetre a year," says Harrison, and the molten outer core is 2,300 km thick.

Gamma-ray burst

Timeframe: there's a nearby binary star called WR 104 that might produce one within 500,000 years, but even if it does it might well miss us

Are we alone in the universe? And if not, why haven't we made contact with alien civilisations yet? Another life destroyer could be to blame: intense waves of radiation called gamma-ray bursts (GRBs).

Many regions of space may have been rendered inhospitable to life

GRBs are formed by intense explosions in space, for instance when a giant star explodes or two stars collide. They can last a fraction of a second, or several minutes. In theory a long GRB could obliterate Earth's ozone layer, leaving the life on the surface exposed to deadly ultraviolet radiation from the Sun.

Many regions of space may have been rendered inhospitable to life by too-frequent GRBs, according to a study published in 2014 by Raul Jimenez at the University of Barcelona in Spain and Tsvi Piran at the Hebrew University of Jerusalem in Israel. But our neighbourhood may be OK. GRBs happen more often near the centre of the galaxy and in regions where stars are densely packed, and Earth is far away from both.

"Life is present due to the fact that Earth is relatively safe from a true damaging long GRB, those which will cause total extinction," says Jimenez. "If Earth was closer by a factor of two to the centre of the galaxy, life would be gone."

That said, Earth may well have experienced the occasional GRB, and there may even be traces of it in the fossil record. About 440 million years ago, many species were wiped out in the Ordovician-Silurian extinction, which some scientists have suggested was triggered by a GRB.

Humans would be wiped out, but other forms of life would go on

But even if that's true, it didn't even get close to killing everything. There has been warning after warning that deadly GRBs could one day wipe out life on Earth, but it's unlikely that any of the potential nearby sources pose a credible threat.

In even more good news, the rate that GRBs occur is decreasing. James Annis at Fermilab in Batavia, Illinois did some number-crunching for this story, and estimates that the average galaxy will now experience just 5 to 50 GRBs every billion years. Since the Milky Way is big, the chances of any coming near Earth are slim.

Even if a rogue GRB did hit Earth, Annis thinks it would be very unlikely to wipe out all life, because sea water is an excellent radiation shield. "I find it really hard to believe that GRBs could kill off sea vent biomes," he says. "I actually find it hard to believe GRBs would kill most ocean fish. I'm more of the opinion GRBs could kill off ground-based life and maybe the larger surface sea life, sort of resetting the evolution clock back before the colonisation of land."

Of course, humans would be wiped out, but other forms of life would go on.

Wandering stars

Timeframe: possibly within the next million years

For billions of years, the planets of our solar system have been performers in a stately dance around the sun. But what would happen if another star came barrelling through? The idea might sound implausible, but in February 2015 researchers led by Eric Mamajek at the University of Rochester in New York announced that it has happened – and surprisingly recently.

Astronomers have identified other stars on a collision course with the solar system

Just 70,000 years ago, around the time our species left Africa, a red dwarf called Scholz's star cruised through the outer reaches of the solar system. It passed through a region called the Oort cloud, a sparse cluster of small, icy lumps that lies far beyond the planets.

Scholz's star was not the first rogue star to pass through the solar system, and it won't be the last. Astronomers have identified other stars on a collision course with the solar system in the next few million years.

Also in February 2015, Coryn Bailer-Jones at the Max Planck Institute for Astronomy in Heidelberg, Germany highlighted two stars that might prove problematic. Hip 85605 is due in our neighbourhood in 240,000 to 470,000 years, while GL 710 will arrive in about 1.3 million years. GL 710 is "a bit bigger than Scholz's star", says Mamajek, but will probably pass further away. Even so, could it, or Hip 85605, threaten life on Earth?

In a word, no. "Just because a star perturbs the Oort cloud, this does not mean the Earth is doomed," says Bailer-Jones.

Things could get hairy if one of those rogue stars went supernova

Either star could push some of the small objects in the Oort cloud onto a collision course with Earth. But as we've already seen, even if some of them did eventually hit our planet, they probably wouldn't destroy all life.

In theory, things could get hairy if a larger rogue star went supernova as it passed through the Oort cloud, sending gamma rays into the inner solar system. "The nearer the supernova, the most intense [the ionising radiation] is. Ten times nearer, 100 times more intense," says Bailer-Jones. "It could be severe enough to cause real harm." But the chances of that "perfect storm" occurring are slim, he says.

A rogue star would also be more dangerous if it passed through the inner parts of the solar system, where the planets are found. But this is again unlikely. "No star we know of has anything but an extremely small probability of entering the inner solar system," says Bailer-Jones. It's too small a target: the distance from the Earth to the Sun is around 50,000 times smaller than the distance to the edge of the Oort cloud.

There are almost certainly organisms that could survive nearly any cataclysm

Researchers can hypothesise almost no end of threats to life on Earth. February 2015 was evidently apocalypse month: another study suggested that we should even worry about the mysterious "dark matter" in our galaxy. We really shouldn't, says Mamajek, given how little we actually know about dark matter. "We don't know what the dark matter particles are, and we don't know how and if they would annihilate to generate energy," he says.

In fact, the take-home message from all of this research is that there isn't a plausible catastrophic agent from outside the solar system that could wipe out life on Earth within the next few billion years. "There are almost certainly organisms that could survive nearly any cataclysm," says Mamajek.

There is nothing to fear but life itself

Timeframe: 500 million years

But there is one agent of destruction that certainly is powerful enough to wipe out swathes of species. Life's biggest threat could come from within, according to Peter Ward at the University of Washington in Seattle.

The microbes living on Earth could not cope, and a massive extinction followed

He calls the idea the Medea hypothesis. The name is a nod to the famous Gaia hypothesis, named for the Greek goddess of the Earth, which suggests that life helps keep Earth habitable. Medea, in stark contrast, is a Greek mythological figure famous for killing her own children. Ward argues that many of the mass extinctions in Earth's history were caused by life.

For instance, about 2.3 billion years ago lots of oxygen was released into the atmosphere by new forms of photosynthetic life. There had never before been free oxygen, so the microbes living on Earth could not cope with it, and a massive extinction followed.

Then there were the first land plants, about 450 million years ago. Plant roots broke up bedrock into soil, speeding up the chemical reaction between minerals in those rocks and carbon dioxide in the atmosphere. This stripped carbon dioxide from the atmosphere and weakened the greenhouse effect, triggering a lethal ice age.

Fast-forward into Earth's distant future, and these kinds of effects could sterilise the planet, says Ward. The sun is getting hotter as it ages, and as a consequence the Earth will warm up. That means the chemical reaction between rocks and atmospheric carbon dioxide will speed up – a process that's accelerated even more by the action of plant roots.

Alien forensic scientists might well conclude that life on Earth had a hand in its own demise

Eventually, so much carbon dioxide will have been removed from the air that plants can no longer perform photosynthesis. All plants will die, and animal life won't be far behind. This could happen surprisingly soon, says Ward, perhaps in just 500 million years.

There would still be microbes, but they'd be vulnerable. "When you're down to a few microbes and you don't have a strong system, that's when physical perturbations could bring about mass sterilisation," says Ward.

Just as in Agatha Christie's Murder on the Orient Express – spoilers for a novel published in 1934 – it would probably take several killers, acting at roughly the same time, to destroy all life on Earth, says Ward. "They could be large impacts, or nearby supernovae, or even something like freezing of the core. No one single event is going to do it." But if a big rock or GRB was to hit Earth after life had culled itself, mass sterilisation might just follow.

Alien forensic scientists might well conclude that life on Earth had a hand in its own demise.

Expanding Sun

Timeframe: between 1 and 7.5 billion years

If none of that gets us, the Sun will. Our home star bathes us in light, and supplies the energy for almost all the life on Earth. But it won't be friendly forever.

As we saw earlier, the Sun is gradually getting hotter. Eventually it will be hot enough to evaporate all Earth's oceans, and cause a runaway greenhouse effect that sends temperatures soaring upwards. This process might begin in about a billion years, and would wipe out all but the most resistant microorganisms.

But that's not all. Beginning around 5 billion years from now, the Sun will expand, becoming a swollen star called a red giant. By 7.5 billion years in the future, its surface will be past where Earth's orbit is now. So the expanding Sun will engulf, and destroy, the Earth.

It's been suggested that Earth might escape. The Sun will lose mass as it grows, so Earth will spiral further out. But according to calculations performed in 2008, this won't be enough to save our planet.

If that's true, the only hope lies with us. If any humans are still around, they might have the technology to move the Earth to safety. Otherwise, life on Earth has a maximum life expectancy of 7.5 billion years.