We develop a theory for the gamma-ray spectrum in a scattering and absorbing medium. Expressions are derived for the spectrum when sources are uniformly distributed in an infinite medium. We express the view that the formation of the spectrum at a point is a local phenomenon, originating from the Compton degradation of high-energy photons which are transported from the source to the neighborhood of the point of interest. This allows one to apply the theory to a point source in an infinite medium, as well as to a geometry appropriate for well logging. Confirming evidence via Monte Carlo results and experiment is presented. We show an application to a well logging device for measurement of gamma-ray absorption via the photoelectric effect, a parameter which is sensitive to lithology.