Before the advent of Modern Science and its ability to explain natural phenomena relatively well, we had no idea how the Sun actually worked. Scientists had no idea that the Sun was just a giant ball of really hot gas that’s able to generate light using its own mass. However, over the course of time and after disproving several probable theories, modern scientists were able to conjure up the best explanation for how the Sun has shined and will continue to shine for billions of years.
As a bit of background, I’ll discuss some of the theories developed in the past and how they helped contribute to the ideas we have today. To start, we know that ancient thinkers had potentially thought that the sun was akin to a fire, in that it was just a lump of coal or wood burning infinitely. However, this idea was not only silly but also easily disprovable — when scientists were able to obtain measurements about the Sun in the 19th century (its size and distance from Earth), they quickly decided that the Sun was not burning, as no object of that size could continually exhaust resources.
Knowing that the Sun couldn’t subsist off of chemical processes, scientists suggested that the Sun could generate its energy from gravitational contraction (meaning that the Sun, as it continuously shrinks in size, would always have gas moving inwards which would create the thermal energy required by the Sun). And, because the Sun was so large, it would only need to shrink a very small amount to generate the required energy. However, scientists pointed out that this gravitational contraction could only occur for up to 25 million years — as we know, the Earth is much older than that. Thus, scientists had to develop a new theory to explain the Sun!
And lastly, after having exhausted both chemical and gravitational processes, modern scientists (like Albert Einstein) realized that mass itself contains a massive amount of energy (as dictated by Einstein’s special relativity equation, E=mc^2). Decades of calculations ensued — however, after details had been worked out, scientists concluded that the Sun generated energy through the process of nuclear fusion. In essence, as a result of gravitational contractions, the Sun’s core was able to reach a hot enough temperature to sustain nuclear fusion. At that point, the Sun experiences two types of equilibrium to maintain the nuclear fusion — those include gravitational equilibrium (for outward gas pressure and inward pull of gravity, i.e. gravitational contraction) and energy balance (equal rates of fusion releasing energy and the surface of the Sun radiating that energy). With these two equilibria contributing to the nuclear fusion process, the Sun will continue to generate energy for the next 5 billion years!