A diffraction grating splits light into its component wavelengths by passing it through (or reflecting it off) thousands of closely spaced parallel slits per millimeter. This calculator applies the grating equation d·sinθ = mλ to find the diffraction angle, the wavelength of an unknown light source, or the spacing of an unknown grating — the same relationship used in spectrometers, monochromators, and physics-lab diffraction demonstrations.
How the grating equation works
When light passes through a series of evenly spaced slits, each slit acts as a source of a new wavefront (Huygens' principle). At most angles, these wavefronts interfere destructively and cancel out. Only at specific angles — where the path-length difference between adjacent slits equals a whole number of wavelengths (mλ) — do the wavefronts interfere constructively and produce a bright fringe. That path-length difference is exactly d·sinθ, giving the grating equation d·sinθ = mλ. Because the equation depends on wavelength, different colors of light diffract to different angles from the same grating, spreading white light into a rainbow spectrum just like a prism, but through interference rather than refraction.
Lines per mm, order, and the angle that results
Diffraction gratings are typically rated by how many lines are ruled per millimeter — common lab gratings run from a few hundred to a few thousand lines/mm. A finer rating (more lines per mm) means a smaller spacing d, which pushes the diffraction angle wider for the same wavelength and order. The order m is simply which bright fringe you're looking at: m = 0 is the straight-through (undeviated) beam, m = 1 is the first bright fringe off to each side, m = 2 the second, and so on — each successive order appears at a larger angle and is generally dimmer than the one before it.
Limits and edge cases
Because sinθ cannot exceed 1, there's a hard ceiling on how many orders a given grating and wavelength combination can produce: m_max = floor(d/λ). Push past that and the grating equation simply has no solution — that order doesn't appear at any angle. This calculator assumes normal incidence (light striking the grating perpendicular to its surface) and an idealized, evenly ruled grating; it does not model grating efficiency, blaze angle effects on reflection gratings, or overlapping orders from mixed-wavelength (polychromatic) sources, all of which matter in precision spectroscopy but go beyond the basic grating equation.