The death of a star is one of the most fascinating topics in astronomy and astrophysics. Throughout its life, a star fights a battle against the force of gravity, which wants to pull in the outer layers of the star and cause it to collapse. This is prevented by nuclear fusion taking place in the core of the star. That provides an outward force against gravity with pressure produced by light and heat. This works as long as nuclear fusion continues.
In a massive star, there is more pressure in the core and so fusion proceeds rapidly and the star can fuse heavier and heavier elements. But this is the cause of the stars death. Nuclear fusion can only proceed up to Iron-56. When the core of a large star becomes composed of Iron, fusion can no longer continue and the pressure that used to keep the star upright is no longer there. The outerlayers collapse against the iron core and rebound-and the result is a supernova, one of the most violent events in the galaxy. Massive stars go through their fuel rapidly, they live fast and die young.
A star like the sun won't have a violent death, but its dramatic nonetheless. The sun is a smaller star, and paradoxically even though it starts out with less fuel it burns it more slowly so lives alot longer. Nuclear fusion of hydrogen in a star like the sun can go on for about 10 billion years, turning the hydrogen in the core into helium. As the helium builds up in the core, the energy output of the sun will decrease causing the outer layers to collapse in a bit causing a rise in pressure. The increased pressure saves the sun for awhile as fusion of helium begins. During this period, the sun will fuse helium into carbon atoms releasing as much as a thousand times more energy than it did when it was fusing hydrogen. This will cause the outer layers of the star to puff out or swell, and the sun will become a red giant perhaps swallowing the earth into its outer layers.
When the sun runs out of helium and fusion stops again, the outer layers will collapse down just like in a big star. But, there is a lot less material so the collapse isn't all that dramatic. The sun will collapse into a "white dwarf" which maintains its shape due to the laws of quantum mechanics, which basically say you can't force two electrons together into the same point of space (the "Pauli exclusion principle"). Since the sun is a lot smaller than a huge star that supernovas, there is not enough force in the collapsing gas layers to overcome the repulsion of the electrons. So the left over matter in the core forms a dense ball and the outer layers of gas kind of puff out into space. The planetary nebula may not be violent and exciting, but the images are quite dramatic. They are the ghosts of the universe, remnants of once vibrant powerful forces of life, stars like the sun.
This has already happened in dramatic fashion throughout the universe. Here are some pictures. The first one is the "cats eye nebula" pictured at the beginning of this article. The outward traveling gases produce an amazing picture, with the dying star at the center. There is some belief that this is actually a binary system. As a star dies, it blows off gas at different times and at different speeds, giving the amazing and unique patterns that make up these beautiful images. The variation in color is due to the differing elemental composition of the gas, for example Oxygen can lead to green colors.
This amazing picture is the Eskimo nebula, taken by the Hubble space Telescope.
Here is another one called IC418.
There is no doubt about it, someday in the distant future our sun will follow the same fate as the stars in these images. Makes you wonder if there was once life on planets that orbited these now dead stars. I wonder what they were like, if they had advanced civilizations, and what became of them. If life on earth gets very advanced maybe they will move to another younger star system or engineer the sun so this won't happen. But that is such a daunting prospect, and there is no evidence any stars have been "engineered", I doubt that will happen.