A song written by Hy Zaret and Lou Singer, later popularized by the band They Might Be Giants, claims that "the sun is a mass of incandescent gas, a gigantic nuclear furnace." Upon closer examination, it appears that this initial classification of the sun is a little too narrow. It turns out that the sun is a complex body that we still don't understand fully.
But here's what we do know: The sun is a massive object comprised of intensely hot, ionized gases. We call this kind of gas plasma and it's the most common state of matter in the universe. The atoms that make up the gases in the sun are so hot that they can't hold on to their electrons. The gases flow in currents through the sun, carrying electrons with them.
If you're familiar with electromagnets, you know that an electrical current can create a magnetic field. That's the case with the sun. The sun has an enormous magnetic field around it. The rotation of the sun perpetuates this magnetic field.
To make matters more complicated, hot objects tend to expand. The sun is an extremely hot object. But the sun is also large and dense, which means it has a strong gravitational pull. The sun's gravity balances out its tendency to expand.
The combination of these forces can cause the sun's surface to change in dramatic and sometimes violent ways. The currents of gas cause magnetic field lines to twist. That can prevent hotter gases from the sun's core from rising to the surface, creating sunspots. Sunspots appear darker than the rest of the sun's surface. They are also cooler than the brighter areas that surround them.
The hot gas trapped beneath sunspots exerts pressure on the magnetic field lines that prevents the gas from reaching the surface. This winds the magnetic field lines into tighter coils. Sometimes, even more field lines become entangled. Once in a while, the magnetic field lines will uncoil without much incident and the sunspot fades as the hot gases rise to the surface. But sometimes the pressure continues to build until the magnetic field lines snap out suddenly, causing a solar flare.