We understand the process of nuclear fusion, and [how stars consume](https://en.wikipedia.org/wiki/Stellar_nucleosynthesis) the material that they have (hydrogen, helium, etc.) in order to shine.
We also understand how materials glow when heated; it’s not white light, it’s only certain frequencies based on the atom and how its electrons absorb and release this heat energy as photons. This lets scientists use [spectroscopy](https://en.wikipedia.org/wiki/Astronomical_spectroscopy) to detect what element a star has, and thus what nuclear reactions are going on inside the star.
So the combination of all this knowledge has led to scientists being able to [classify stars](https://en.wikipedia.org/wiki/Stellar_classification). So using just the brightness and spectral lines, astronomers can tell what kind of star it is, and get a pretty good estimate of its size and thus how much of the fuel has been consumed (the age of the star).
Latest Answers