Low-mass stars spend millions of years as protostars collapsing under gravity before arriving on the main sequence. Massive stars collapse more rapidly, in as little as 10,000 years. Once on the main sequence, a star's lifetime depends on its mass - low-mass stars can spend billions of years fusing hydrogen, while high-mass stars may last only a few million years. Eventually a star exhausts its hydrogen fuel and expands as a red giant, then moves to the horizontal branch fusing helium before becoming an asymptotic giant branch star and ending its life as a planetary nebula or white dwarf.