The grating equation is a mathematical relationship that describes the angles at which light is diffracted by a grating, expressed as $d \sin(\theta) = m \lambda$, where $d$ is the grating spacing, $\theta$ is the angle of diffraction, $m$ is the order of the diffraction, and $\lambda$ is the wavelength of light. This equation connects the physical properties of light with its interaction with structures like diffraction gratings, providing insight into the formation of spectra.