Online Astronomy eText: The Sun
Heat Flow in the Solar Interior

Changes in Brightness, Temperature, Pressure and Density
      The energy of the Sun is produced in the core (the innermost 10% or so of its mass and radius), through the fusion of hydrogen to helium. It then flows outward, toward the surface, where it is radiated into space. On the average, heat must be created in the core, flow from layer to layer, and then be lost at the surface, at the same rate. Otherwise, various parts of the gases in the solar interior will heat up and expand, or cool off and contract.
      To ensure that the flow is more or less constant, the brightness of the Sun must increase, as you go inward, by about the same brightness that it has at the surface, for each "layer" downwards (a layer being defined as approximately the distance that you can see downwards, at any given point).
      To see how this works, imagine that you are at the surface of the Sun. Heat is flowing in all directions, at a rate of a little over 5 million watts per square foot (the luminosity of the Sun, a little less than 400 trillion trillion watts, divided by its surface area, a little more than 70 million trillion square feet). As heat flows outwards, into space, it must be replaced by heat from below, so there must be a net outflow of a little over 5 million watts per square foot from the layer below the surface, to the surface. But in the region below the surface, heat is flowing in two directions -- downwards, at the surface heat flow rate, from the surface, and upwards, at the heat flow rate for the next layer down, toward the surface. Therefore, in order for the net heat flow outward to equal the surface heat flow, the heat flow from the layer below the surface must be twice as great as that at the surface.
      The above discussion is a bit simplified, in a number of ways, but leads to the conclusion that, as we head into the Sun, each layer must be brighter than the layer above it, by an amount approximately equal to the surface brightness. As a result, by the time that we are in the center, approximately 15 trillion layers below the surface (defining each layer as the distance that you can see, from the layer above), the brightness must be of the order of 15 trillion times greater, per square foot, than at the surface.
      To accomplish this increase in brightness, the temperature must increase, and as a result, every step of the way down into the Sun, a number of quantities must increase -- the brightness, the temperature, the density, and the pressure.
      The increase of brightness, and the corresponding increase in temperature, are summarized above. The increase in pressure is required, because the pressure must everywhere be equal to the weight of the gases above a given region, and of course, the further down you are, the greater that weight will be. The increase in density is required because to increase the pressure, you need to increase either the density or the temperature, or both, and as it turns out, the temperature doesn't increase fast enough to take care of the problem. At the center, the temperature is only about 2500 times hotter than at the surface, while the pressure is hundreds of billions of times greater. As a result, the density has to increase by many times (many tens of millions of times), making up the bulk of the way in which pressure increases.

The Flow of Radiation
      The outward flow of radiation from the core is continually blocked by collisions with the gas particles in the interior of the Sun (primarily the electrons, which "look" much larger than the nuclei, and are therefore more effective at blocking the light). Near the surface, the gas is spread out, and the light photons may travel several miles between collisions, allowing us to see a long distance -- but near the center of the Sun, the gas is extremely dense (more than 100 times the density of water), and the light photons travel only a fraction of an inch between collisions.
      Since, from the deep interior, every direction is "out", if the light could just keep going in a given direction for any length of time, it could escape from the Sun in very little time (in fact, in less than 3 seconds). But because the light bounces from particle to particle, over and over and over again, its total path length is tremendously increased (in fact, by about the number of "layers" that it has to pass through, or about 15 trillion times), slowing it down tremendously (by the same huge factor), and causing it to take more like 40 trillion seconds, which is more than a million years.
      Since the light takes so long to get out of the Sun, and has to undergo so many collisions (approximately the square of the number of layers, or about 200 trillion trillion collisions per photon), it would hardly be surprising if it was in some way affected by its passage through the gas. And, in fact, in any given part of the Sun, the continual interaction between the light and the gas results in something called Local Thermodynamic Equilibrium -- namely, on the average, all measures of temperature, such as the average energy of motion of the gas, or the average energy of the light photons, must be about the same.
      To see how this works, imagine that we take two gases, a cold one and a hot one, and mix them together. In the cold gas, the particles are moving slowly, with low energies, and in the hot gas, the particles are moving quickly, with high energies. As the particles of the two gases collide, energy is exchanged, with an average transfer from the more energetic particles to the less energetic ones (only on the average -- sometimes it works the other way around), causing the mixed gas to end up with average energies for the particles, and their motions, and a corresponding average, or in this case, lukewarm temperature.
      The same thing happens if a "gas" consisting of photons passes through a gas consisting of ordinary particles, such as atomic nuclei and free electrons. In most of the collisions between the photons and the gas particles, nothing will happen, save a random change in the direction of motion of the photons, but in a very small fraction of the collisions, there will be an exchange of energy, and if there are enough such exchanges, the average energy of the photons and of the gas particles will become equal.
As a result, on its long journey from the center of the Sun, where the temperatures (and the gas particle energies) are very high, toward the outer layers where the temperatures (and the gas particle energies) are low, the photons passing through the gas are gradually transformed from high-energy photons to low-energy photons. Note that the TOTAL energy doesn't change -- so the number of photons must gradually increase -- but the mechanism by which that is accomplished is outside the scope of this brief discussion.
      So, in the core of the Sun, we have very high temperature gases, in which nuclear fusion reactions are taking place, creating gamma radiation (as discussed in your text). As the radiation (photons) streams through the gas, it is quickly transformed into radiation which has an average energy spectrum equal to that of the gas through which it is moving, and then, over the next million years or so, as it slowly diffuses (randomly moves from place to place, spreading throughout the Sun) toward the surface, it gradually transforms, at each step of its journey, so that it is always in equilibrium with its surroundings.