The continuity equation describes the distribution of electrons and holes in a semiconductor when there is generation, recombination, and carrier movement. It states that the rate of change of carriers inside the semiconductor equals the rate entering minus the rate leaving, plus the rate of generation minus the rate of recombination. The continuity equation is derived by considering the carrier flux into and out of an infinitesimal volume of the semiconductor. Under certain approximations, the continuity equation can be simplified to the minority carrier diffusion equations, which describe the behavior of excess carriers in the semiconductor.