Theoretical and experimental results for the temperature dependence of amplified spontaneous emission (ASE) in laser diodes (LD's) and light-emitting diodes (LED's) are presented. Our theoretical model takes into account conduction band nonparabolicity and band-gap renormalization. The gain spectrum is calculated from the theoretical spontaneous emission spectrum and both compare very well with experimental data. From a fit to the observed temperature dependence of ASE for a LED and the gain spectrum for a LD with an identical structure as the LED except for mirror reflectivity we are able to establish carrier density as a function of injection current for both devices. We show that photons fluctuating into cavity modes give rise to substantial subthreshold carrier pinning in laser diodes. These fluctuations extract an extra current from the device and play an increasingly important role with increasing temperature.