Post–main sequence
As stars of at least 0.4 M☉ exhaust the supply of hydrogen at their core, they start to fuse hydrogen in a shell surrounding the helium core. The outer layers of the star expand and cool greatly as they transition into a red giant. In some cases, they will fuse heavier elements at the core or in shells around the core. As the stars expand, they throw part of their mass, enriched with those heavier elements, into the interstellar environment, to be recycled later as new stars. In about 5 billion years, when the Sun enters the helium burning phase, it will expand to a maximum radius of roughly 1 astronomical unit (150 million kilometres), 250 times its present size, and lose 30% of its current mass.
As the hydrogen-burning shell produces more helium, the core increases in mass and temperature. In a red giant of up to 2.25 M☉, the mass of the helium core becomes degenerate prior to helium fusion. Finally, when the temperature increases sufficiently, core helium fusion begins explosively in what is called a helium flash, and the star rapidly shrinks in radius, increases its surface temperature, and moves to the horizontal branch of the HR diagram. For more massive stars, helium core fusion starts before the core becomes degenerate, and the star spends some time in the red clump, slowly burning helium, before the outer convective envelope collapses and the star then moves to the horizontal branch.
After a star has fused the helium of its core, it begins fusing helium along a shell surrounding the hot carbon core. The star then follows an evolutionary path called the asymptotic giant branch (AGB) that parallels the other described red-giant phase, but with a higher luminosity. The more massive AGB stars may undergo a brief period of carbon fusion before the core becomes degenerate. During the AGB phase, stars undergo thermal pulses due to instabilities in the core of the star. In these thermal pulses, the luminosity of the star varies and matter is ejected from the star's atmosphere, ultimately forming a planetary nebula. As much as 50 to 70% of a star's mass can be ejected in this mass loss process. Because energy transport in an AGB star is primarily by convection, this ejected material is enriched with the fusion products dredged up from the core. Therefore, the planetary nebula is enriched with elements like carbon and oxygen. Ultimately, the planetary nebula disperses, enriching the general interstellar medium. Therefore, future generations of stars are made of the "star stuff" from past stars.
During their helium-burning phase, a star of more than 9 solar masses expands to form first a blue supergiant and then a red supergiant. Particularly massive stars (exceeding 40 solar masses, like Alnilam, the central blue supergiant of Orion's Belt) do not become red supergiants due to high mass loss. These may instead evolve to a Wolf–Rayet star, characterised by spectra dominated by emission lines of elements heavier than hydrogen, which have reached the surface due to strong convection and intense mass loss, or from stripping of the outer layers.
When helium is exhausted at the core of a massive star, the core contracts and the temperature and pressure rises enough to fuse carbon (see Carbon-burning process). This process continues, with the successive stages being fueled by neon (see neon-burning process), oxygen (see oxygen-burning process), and silicon (see silicon-burning process). Near the end of the star's life, fusion continues along a series of onion-layer shells within a massive star. Each shell fuses a different element, with the outermost shell fusing hydrogen; the next shell fusing helium, and so forth.
The final stage occurs when a massive star begins producing iron. Since iron nuclei are more tightly bound than any heavier nuclei, any fusion beyond iron does not produce a net release of energy.
Some massive stars, particularly luminous blue variables, are very unstable to the extent that they violently shed their mass into space in events known as supernova impostors, becoming significantly brighter in the process. Eta Carinae is known for having undergone a supernova impostor event, the Great Eruption, in the 19th century.
As a star's core shrinks, the intensity of radiation from that surface increases, creating such radiation pressure on the outer shell of gas that it will push those layers away, forming a planetary nebula. If what remains after the outer atmosphere has been shed is less than roughly 1.4 M☉, it shrinks to a relatively tiny object about the size of Earth, known as a white dwarf. White dwarfs lack the mass for further gravitational compression to take place. The electron-degenerate matter inside a white dwarf is no longer a plasma. Eventually, white dwarfs fade into black dwarfs over a very long period of time.
In massive stars, fusion continues until the iron core has grown so large (more than 1.4 M☉) that it can no longer support its own mass. This core will suddenly collapse as its electrons are driven into its protons, forming neutrons, neutrinos, and gamma rays in a burst of electron capture and inverse beta decay. The shockwave formed by this sudden collapse causes the rest of the star to explode in a supernova. Supernovae become so bright that they may briefly outshine the star's entire home galaxy. When they occur within the Milky Way, supernovae have historically been observed by naked-eye observers as "new stars" where none seemingly existed before.
A supernova explosion blows away the star's outer layers, leaving a remnant such as the Crab Nebula. The core is compressed into a neutron star, which sometimes manifests itself as a pulsar or X-ray burster. In the case of the largest stars, the remnant is a black hole greater than 4 M☉. In a neutron star the matter is in a state known as neutron-degenerate matter, with a more exotic form of degenerate matter, QCD matter, possibly present in the core.
The blown-off outer layers of dying stars include heavy elements, which may be recycled during the formation of new stars. These heavy elements allow the formation of rocky planets. The outflow from supernovae and the stellar wind of large stars play an important part in shaping the interstellar medium.
Binary stars' evolution may significantly differ from that of single stars of the same mass. For example, when any star expands to become a red giant, it may overflow its Roche lobe, the surrounding region where material is gravitationally bound to it; if stars in a binary system are close enough, some of that material may overflow to the other star, yielding phenomena including contact binaries, common-envelope binaries, cataclysmic variables, blue stragglers, and Type Ia supernovae. Mass transfer leads to cases such as the Algol paradox, where the most-evolved star in a system is the least massive.
The evolution of binary star and higher-order star systems is intensely researched since so many stars have been found to be members of binary systems. Around half of Sun-like stars, and an even higher proportion of more massive stars, form in multiple systems, and this may greatly influence such phenomena as novae and supernovae, the formation of certain types of star, and the enrichment of space with nucleosynthesis products.
The influence of binary star evolution on the formation of evolved massive stars such as luminous blue variables, Wolf–Rayet stars, and the progenitors of certain classes of core collapse supernova is still disputed. Single massive stars may be unable to expel their outer layers fast enough to form the types and numbers of evolved stars that are observed, or to produce progenitors that would explode as the supernovae that are observed. Mass transfer through gravitational stripping in binary systems is seen by some astronomers as the solution to that problem.