Enjoy the sun while it lasts: in 5 billion years’ time, our host star will burn out, rip itself apart and turn into a massive glowing ring of interstellar gas and dust, scientists say.

Astronomers have long known that the sun will die when it runs out of fuel, but the precise nature of its death throes has been far from clear, even to the most morbid of the field’s practitioners.

Now an international team of scientists have worked out the details. Using a new computer model, they found that rather than simply fading away as previously thought, the dying sun will transform into a stunning planetary nebula visible for millions of light years around.

“These planetary nebulae are the prettiest objects in the sky and even though the sun will only become a faint one, it will be visible from neighbouring galaxies,” said Albert Zijlstra, professor of astrophysics at the University of Manchester. “If you lived in the Andromeda galaxy 2 million light years away you’d still be able to see it.”

The sun is in many ways an average star. It is middling in size and, at 5 billion years old, halfway through its lifetime. The end will come when the sun’s core runs out of hydrogen, causing its centre to collapse. When this happens, nuclear reactions will start up outside the core, causing the sun to swell into a red giant that eventually engulfs Mercury and Venus.

But that is not the end of the story. Writing in the journal Nature Astronomy, Zijlstra and colleagues in Poland and Argentina describe what will happen next. After forming a red giant, the sun will lose about half of its mass as the outer layers are blown off at about 20km per second. The core will then heat up rapidly, making it radiate ultraviolet light and x-rays that catch up with the outer layers and turn them into a brightly glowing ring of plasma. The planetary nebula will shine for about 10,000 years.

While older computer models predicted the sun would lose its outer layers at the end of its life, they also showed that the core would heat up too slowly to make the lost layers glow. By the time the core reached the required temperature of 30,000C in those models, the outer layers would be long gone, and dispersed into the gas and dust that drifts between the stars.

“What we’ve shown is that the core will be hot enough in five to 10 thousand years after the outer layers have been ejected, and that is quick enough,” said Zijlstra. “The sun is right on the lower limit of being able to form a planetary nebula.”

While the Earth may survive the death of the sun, life on the planet will have been extinguished long beforehand. As the sun ages, it will grow steadily brighter, and in the next 2 billion years it could become hot enough to boil the oceans. “It won’t be a very pleasant place,” said Zijlstra.