Stars are powered by nuclear fusion, which is the process of smashing atomic nuclei together to create heavier elements. Stars like our Sun produce most of their energy by converting hydrogen to helium in their cores. This process releases energy in the form of light, which causes the stars to shine brightly. Stars like our Sun have enough hydrogen fuel to burn for about 10 billion years.
Stars more massive than our Sun also undergo nuclear fusion, but since they have more mass their cores are hotter and denser, and nuclear fusion proceeds more rapidly. After they convert all of their hydrogen to helium they begin to fuse the helium into carbon and other heavier elements, and so on. Each successive phase of fusion requires a higher temperature to proceed, so only the most massive stars will produce all of the heavier elements. Fusing heavier elements produces less energy per reaction each time, and producing elements heavier than iron actually requires more energy than it produces. Therefore, no matter how massive the star is nuclear fusion stops once iron is produced, and the star will then collapse in a supernova explosion.