It took us about 4.6 billion years to get from a large, free-floating molecular cloud to the present day. Our sun is likely well past middle age now and unfortunately might only have a few billion more years left in it before things start to fall apart.
So what happens once it starts to run out of fuel? Will it expand to consume the Earth? Will it go supernova or collapse into a black hole? The answers to these questions are largely speculation for now, but there are some things we do know about how our solar system will come to an end.
The N-Body Problem and the next five billion years
It is nearly impossible to project what the next five billion years will look like with any pretense to accuracy.
One issue is the N-Body Problem - the challenge of predicting the motions of more than two objects that all have independent gravitational effects on one another. We simply don't have the math to calculate this problem with any sufficient accuracy beyond a few million years.
The slightest error in trajectory now, say a rounding error created by not having enough bits to represent a data point in an orbital function with 100% accuracy, will have an enormous impact on what our projections will be when carried through to even 100 million years, much less the next five billion.
This means that we simply can't say exactly what's going to happen to the planets in the next five billion years. A perturbation in Jupiter's orbit could send it slightly closer to the inner solar system, enough to disrupt the asteroid belt and the orbit of Mars.
This disruption could end up sending Mars on a more elongated elliptical orbit around the Sun, which could end up sling-shotting Mars out of the solar system entirely within the next billion years. While this doesn't seem likely based on what we know, the problem is what we don't know.
Just as a rounding error could transform the positions of all the known planets and maybe even send one or two of them flying out into interstellar space, a variable we haven't accounted for in our models could prove just as significant.
A passing star that gets within a few dozen light-years of our solar system could exert enough of a gravitational tug to disrupt the order of the solar system and send a planet or two slingshotting out of the solar system.
These disruptions could amount to nothing, or they could send planets with stable orbits into chaos. And let's not even talk about the possibility of a stellar-mass black hole tumbling through the neighborhood. It could send everything into a tailspin and we'd never even know it was there.
But, there are some things that we do know will happen with much greater certainty.
First, in as soon as a few hundred million years, enough helium (the product of hydrogen fusion) will accumulate in the Sun's core to make it harder for the sun to efficiently burn hydrogen. As a result, the Sun will have more trouble keeping the crushing weight of its atmosphere at bay.
This pressure will force more hydrogen into its core as fuel for fusion, which will, in turn, ramp up its temperature and push back against the pressure of its atmosphere.
To those of us out in the rest of the solar system, this means that the Sun will grow brighter and hotter than it is now, which will have major implications for the inner planets, and, from our perspective, for one planet in particular.
The temperature change needn't be large before all of the liquid water on Earth begins to evaporate at an accelerated rate, dramatically altering our water cycle. Before long, the oceans will boil off entirely, shrouding the Earth in a thick layer of cloud cover that traps in heat and turns Earth into a furnace, much like Venus.
Also, within the next four billion years, the Milky Way will begin its merger with the Andromeda galaxy (M31`), a process that won't be complete until about 5.6 billion years from now. Much like the N-Body Problem, it's impossible to model how our own solar system will fare in all of this, though it's obviously going to have some impact.
The only other thing we know will happen in the next five billion years for sure is that the Sun is going to continue to burn through a massive and steady supply of hydrogen to power its nuclear fusion. Until it runs out, obviously.
Death of the Sun: Stage one — goodbye hydrogen!
About five billion years from now, the Sun will burn through its remaining hydrogen, and things will start to get real for the solar system. When hydrogen fusion grinds to a halt, the weight of the Sun's mass will press inward on the helium byproduct in the core.
At some point, the pressure on the helium will become strong enough to fuse it into beryllium and then into carbon and oxygen. At this point, the energy released will be larger than even that generated by hydrogen fusion, which will push the mass of the Sun's atmosphere outward by 100 or even 1,000 times the diameter of the Sun.
The amount of energy being released won't be 100 to 1,000 times greater though, so the energy will be dissipated over, and radiate from, a significantly wider surface area. This will actually lead to the surface of the red giant stage of the Sun to be cooler than the Sun is today, and give it a redder tinge (though it would still look orange to any humans left around to observe it).
Without a doubt, the swelling of the Sun into a red giant will consume Mercury and Venus, though there is debate about the fate of the Earth in this scenario.
Will Earth be swallowed up by the Sun?
Depending on how far the Sun swells up when it becomes a red giant, either the Earth will be consumed along with Mercury and Venus, or it could be pushed farther back towards the orbit of Mars by the energy released by the Sun's transformation.
It's more likely to be swallowed up though, as more aggressive models of the Sun's red giant phase has it swelling as far out as the asteroid belt, which would have it consuming the entire inner solar system.
More conservative models would have it stop just short of consuming the Earth, but the Earth wouldn't escape unscathed in this instance.
The radiation and heat from the surface of the red giant — cooler, but significantly closer — would be enough to turn the rocky minerals and silicates of the Earth's crust and mantle into liquid and gas. These would then be stripped away by the intense solar winds of the red giant, leaving nothing but the Earth's iron core behind.
What about the rest of the Solar System?
Few believe that Mars will be consumed by our sun's transformation into a red giant, but assuming it survives, it will be orbiting so close to the sun that it might have wished it had.
Further out, the four gas giants are expected to be pushed back to varying degrees, and Jupiter and Saturn are expected to swell in size as they feed on the solar winds that are dumping far more material their way by virtue of their increased proximity.
Unfortunately, Saturn's rings are pretty much done for since they are almost entirely made of ice, as are the rings of the other gas giants. The intense heat from the red giant is going to melt them pretty much straight away, leaving behind what little rocky material there is or possibly nothing at all.
The frozen moons of Jupiter and Saturn will also melt, exposing their oceans for the first time ever and evaporating them along with Saturn's rings. Whatever life existed there will not survive. Some moons might disappear entirely as their volatiles melt and get blown away by the solar winds.
Uranus and Neptune could be in for some trouble of their own as their orbital disruptions will push them closer to Planet Nine's orbit (if it exists), which over time will create an unpredictable N-body gravitational disruption that could even see one or two of the planets ejected from the solar system.
Interestingly, the habitable zone of the solar system will be wider, but it will be pushed back so far that it might encompass parts of the Kuiper belt, with Pluto experiencing the same average temperatures as Earth does today.
This will be especially interesting, as that part of the solar system is full of complex organic compounds similar to those that first gave rise to life on Earth along with an enormous amount of real estate in which it could develop into life.
This red giant phase should last for about one to two billion years, giving ample time for life to take root on more potential worlds in the solar system than currently exist now. The same event that destroys the inner planets could also lead to an unprecedented flourishing of life in our distant solar system.
Or, these places could be stripped of their volatiles and atmospheres as well, leaving nothing behind but warm rocks in a dimmer orange glow.
Death of the Sun: Stage two — there goes the helium
Assuming that unknown factors haven't thrown all of the planets out of the solar system, whatever remains at roughly the seven to eight billion-year mark will see the actual death of a star.
Once the red giant has burned through nearly all its helium fuel in its core, nuclear fusion will start to flicker. When not enough fusion takes place to push back against the mass of the red giant bearing down on the core, the red giant will start to collapse, but it will happen in stages.
As the collapsing material presses in, the remaining hydrogen and helium in the solar shell that did not get convected into the Sun's core and fused into heavier elements will be pushed off the core in a series of explosive pulses.
In this way, the white dwarf now buried inside the remains of the red giant will shed the last of this material into a spectacular planetary nebula (or at least it will appear spectacular for any sentient life looking at our solar system from a distance).
What remains will be about 50 percent of the original mass of the Sun, compressed by gravity into roughly the size of the Earth. By official standards, the Sun is now dead, held up against total collapse by a quantum phenomenon known as electron degeneracy.
This white dwarf will start out as extremely hot, and blasting out X-ray radiation. But within a billion years or so, it will settle down to more manageable temperatures.
There will be a habitable zone around the white dwarf, but it is almost a certainty that whatever planet could have existed there would have been destroyed by the Sun's red giant phase.
Whatever habitable zone existed during the red giant phase of the Sun's existence will find itself as cold as Neptune or Pluto is today in very short order. If life had earlier risen in those distant parts of the Kuiper belt, it will now freeze to death.
For all intents and purposes, the solar system will be a graveyard of frozen, shattered worlds.
Death of the Sun: Terminal stage — Sun's corpse starts to cool
The incredible compression of half the Sun's mass into a volume the size of Earth will ramp up its temperature to incredible heights, way beyond what the red giant phase of the Sun's life span was capable of.
The surface of the carbon-oxygen white dwarf star will be as high as 20,000 Kelvin, or about six to seven times the surface temperature of the Sun's red giant phase and about three to four times the temperature of the surface of the Sun in its main sequence phase.
Its gravity will also be tremendous. Given that it will be about the same size as Earth, its gravity will be roughly 250,000 to 350,000 times greater than Earth's, making it one of the strongest gravitational bodies in the universe, outmatched only by neutron stars and black holes.
As soon as the white dwarf sheds its outer layers, it will begin to cool, a process that will take trillions of years. This is because a body can only radiate away heat from its surface, and the surface area of a white dwarf is minuscule compared to that of the Sun's main sequence phase and red giant phase.
Gravity will still operate as normal, though, and whatever planets or bodies remain after all this time will continue to orbit the white dwarf. Eventually, they may get pulled closer, until the tidal forces of the white dwarf tear it apart, leaving a dusting of elemental debris on the surface of the star.
Alternatively, the gravitational forces of other passing stars will pull the planets out of stable orbits and eventually send them sling-shotting out of the solar system to become rogue planets.
Eventually, whatever is within the gravitational range of the white dwarf will get pulled in, and whatever is on the periphery or beyond will get pulled away by other bodies large enough to exert an influence on them.
The white dwarf could also fall prey to a dwindling number of black holes and get torn apart and consumed, but the odds of that decrease with time.
Assuming it evades the terminal pull of a passing black hole, the white dwarf will float through the emptiness of space, subjected to strong gravitational interactions with similarly dense bodies in a replay of the N-Body Problem yet again, this time with the white dwarf itself. Such an event could send it hurtling out of the galaxy entirely and into intergalactic space.
Regardless of where it ends up, as it cools, the white dwarf's light will dim. When the last of its heat crosses below the visible light spectrum, all that will be left is a cold lump of carbon and oxygen known as a black dwarf.
It won't be alone though, as the light of all of our stellar neighbors in our galaxy's local group will have faded as well, and the distant galaxies will have sped too far away from us to be seen anymore. Whatever black holes existed will have long since evaporated, due to Hawking radiation, leaving only the lightless corpses of stars to float in an endless void. Total darkness will reign.
The permanent death of the Sun: Either a bang or the long sleep
There are three possible endings to the story of our Sun once it becomes a black dwarf. If it's lucky, it will come across and merge with a red dwarf star or a brown dwarf, and with a fresh source of hydrogen, it can reignite fusion once again and get a second life for many millions of years before burning out again.
Another possibility is that it would come into contact with a nebula or molecular cloud, in which case the accretion of hydrogen and helium would ignite a burst of fusion called a nova, a fireworks display in the grand scheme of things, and little more.
One other possibility is that the immensely dense black dwarf interacts with another black dwarf and the two get caught in each other's gravity.
They'll orbit a common center of gravity in ever-tightening circles until the two collide, unleashing their potential energy in a spectacular supernova and obliterating each other in the process.
And that will be that. All good things must come to an end, and nothing, not even a star, lasts forever.