Why does the spectrum of Sun follow a black-body distribution curve? Black-body radiation, as I understand it, is radiation in thermal equilibrium at a fixed temperature with a cavity. The spectrum of such radiation follows the famous black-body distribution curve. But quite surprisingly to me, the radiation coming from the surface of the Sun also follows the black-body curve despite the radiation does not seem to be in equilibrium. Why is this so?
A related question is a bulb filament, I think, also obeys black body spectrum. But there too, the filament is not in thermal equilibrium. What is the flaw in my understanding?
 A: Imagine a large number of atoms or ions, each allowed to oscillate about their equilibrium positions at high frequency and bounce off one another. We bathe those atoms in electromagnetic radiation, so that energy gets shared back and forth between the atoms and the radiation until their vibrations (which absorb and emit radiation in discrete quanta) come into dynamic equilibrium with the radiation bath.
When this occurs, the resulting energy distribution takes the form of the black body spectrum regardless of what kind of atoms are present. The distribution has a hump in the middle and the peak of that hump represents the temperature of the system, which is associated with the most likely energy that the atoms or ions and the radiation itself will assume after the back-and-forth sharing has gone to completion.
In the outermost layers of the sun, the radiation bath is well-mixed with the kinetic energies of the atoms and ions zooming around and the result is a frequency distribution with a peak corresponding to a temperature of about 5800 degrees kelvin.
The photons that stream off into space with that energy distribution are immediately replaced with more photons from deeper in the sun's "surface" which are equilibrated with the matter present and the spectral distribution is maintained.
A: It is very important to understand what we mean by thermal equilibrium when we talk about black body radiation. Thermal equilibrium is meant to say that inside the body, all particles energy level distributions, speed distributions, are the same, and can be characterized by a single value.

That is, its energy level distributions, particle speed distributions (etc.) must be in equilibrium and characterised by a single temperature. Furthermore, the radiation field must also be in equilibrium with the matter at the same single temperature.
Whilst for the interior of the Sun, this is a very good approximation, near the surface it is not, because radiation can escape and the temperature changes with depth on a length scale comparable with the mean free path of the photons. As a result it is better to think of the Sun as emitting blackbody radiation from different layers at different temperatures.

Is sun a black body?
Now you are saying that the sun emits "the radiation coming from the surface of the Sun also follows the blackbody curve" its radiation from the surface, while it seems so to a external observer like us, the photons actually are produced inside the core and make their way through.

Black body radiation is thermal radiation of a hypothetical body that has everywhere the same temperature and is a perfect absorber. Of all bodies at the same temperature, it has the most intense thermal emission at any frequency. The spectrum is smooth, without any lines or peaks or holes, but it drops to zero for zero and infinite frequency as well.

Blackbody radiation Vs thermal radiation
So the answer to your question is, as you see the Sun satisfies all these requirements, it has everywhere the same temperature (at its surface) as seen for an outside observer like us, and the spectrum is smooth, without any peaks or holes.
But if you want to be very specific, you need to think of the Sun as emitting black body radiation at different temperatures from different layers.
A: This can be considered a comment.

Although planets and stars are neither in thermal equilibrium with their surroundings nor perfect black bodies, black-body radiation is used as a first approximation for the energy they emit

The black body radiation curve is a first approximation to the radiation of a body of matter.Sometimes it fits well, some times not ( as for example for gases). The best fit to the black body radiation curve is seen in the cosmic microwave backround.
In my opinion, considering that thermodynamics emerges from statistical mechanics, even if the conditions of thermodynamic equilibrium are partially, in a time dt, obeyed, the shape would be expected. But maybe you can get an answer from an expert on the subject.
