In optics, a diffraction grating is a grating with a periodic structure of appropriate scale so as to diffract light, or another type of electromagnetic radiation, into several beams traveling in different directions (i.e., different diffraction angles) known as diffracted orders. The emerging coloration is a form of structural coloration. The directions or diffraction angles of these beams depend on the wave (light) incident angle to the diffraction grating, the spacing or periodic distance between adjacent diffracting elements (e.g., parallel slits for a transmission grating) on the grating, and the wavelength of the incident light. Because the grating acts as a dispersive element, diffraction gratings are commonly used in monochromators and spectrometers, but other applications are also possible such as optical encoders for high-precision motion control and wavefront measurement.

For typical applications, a reflective grating has ridges or "rulings" on its surface while a transmissive grating has transmissive or hollow slits on its surface, Such a grating modulates the amplitude of an incident wave to create a diffraction pattern. Some gratings modulate the phases of incident waves rather than the amplitude, and these types of gratings can be produced frequently by using holography.

James Gregory (1638–1675) observed the diffraction patterns caused by a bird feather, which was effectively the first diffraction grating (in a natural form) to be discovered, about a year after Isaac Newton's prism experiments.Letter from James Gregory to John Collins, dated 13 May 1673. Reprinted in: especially p. 254 The first human-made diffraction grating was made around 1785 by Philadelphia inventor David Rittenhouse, who strung hairs between two finely threaded screws.Thomas D. Cope (1932) "The Rittenhouse diffraction grating". Reprinted in: (A reproduction of Rittenhouse's letter re his diffraction grating appears on pp. 369–374.) This was similar to notable German physicist Joseph von Fraunhofer's wire diffraction grating in 1821. The principles of diffraction were discovered by Thomas Young. (Note: This lecture was presented before the Royal Society on 24 November 1803.) and Augustin-Jean Fresnel. reprinted as (Revision of the "First Memoir" submitted on 15 October 1815).Fresnel, Augustin-Jean (1818), "Mémoire sur la diffraction de la lumière" ("Memoir on the diffraction of light"), deposited 29 July 1818, "crowned" 15 March 1819, published in Mémoires de l'Académie Royale des Sciences de l'Institut de France, vol.  (for 1821 & 1822, printed 1826), pp. 339–475; reprinted in Oeuvres complètes d'Augustin Fresnel, vol. 1 (Paris: Imprimerie Impériale, 1866), pp. 247–364; partly translated as "Fresnel's prize memoir on the diffraction of light", in H.Crew (ed.), The Wave Theory of Light: Memoirs by Huygens, Young and Fresnel, American Book Company, 1900, pp. 81–144. (First published, as extracts only, in Annales de Chimie et de Physique, vol. 11 (1819), pp. 246–96, 337–78.) Using these principles, Fraunhofer was the first to use a diffraction grating to obtain line spectra and the first to measure the wavelengths of spectral lines with a diffraction grating.

In the 1860s, state-of-the-art diffraction gratings with small groove period, , were manufactured by Friedrich Adolph Nobert (1806–1881) in Greifswald; then the two Americans Lewis Morris Rutherfurd (1816–1892) and William B. Rogers (1804–1882) took over the lead. By the end of the 19th century, the concave gratings of Henry Augustus Rowland (1848–1901) were the best available.

A diffraction grating can create "rainbow" colors when it is illuminated by a wide-spectrum (e.g., continuous) light source. Rainbow-like colors from closely spaced narrow tracks on optical data storage disks such as CDs or DVDs are an example of light diffraction caused by diffraction gratings. A usual diffraction grating has parallel lines (It is true for 1-dimensional gratings, but 2 or 3-dimensional gratings are also possible and they have their applications such as wavefront measurement), while a CD has a spiral of finely spaced data tracks. Diffraction colors also appear when one looks at a bright point source through a translucent fine-pitch umbrella fabric covering. Decorative patterned plastic films based on reflective grating patches are inexpensive and commonplace. A similar color separation seen from thin layers of oil (or gasoline, etc.) on water, known as iridescence, is not caused by diffraction from a grating but rather by thin film interference from the closely stacked transmissive layers.

Theory of operation

For a diffraction grating, the relationship between the grating spacing (i.e., the distance between adjacent grating grooves or slits), the angle of the wave (light) incidence to the grating, and the diffracted wave from the grating is known as the grating equation. Like many other optical formulas, the grating equation can be derived by using the Huygens–Fresnel principle, stating that each point on a wavefront of a propagating wave can be considered to act as a point wave source, and a wavefront at any subsequent point can be found by adding together the contributions from each of these individual point wave sources on the previous wavefront.

Gratings may be of the 'reflective' or 'transmissive' type, analogous to a mirror or lens, respectively. A grating has a 'zero-order mode' (where the integer order of diffraction is set to zero), in which a ray of light behaves according to the laws of reflection (like a mirror) and refraction (like a lens), respectively.

An idealized diffraction grating is made up of a set of slits of spacing , that must be wider than the wavelength of interest to cause diffraction. Assuming a plane wave of monochromatic light of wavelength at normal incidence on a grating (i.e., wavefronts of the incident wave are parallel to the grating main plane), each slit in the grating acts as a quasi point wave source from which light propagates in all directions (although this is typically limited to the forward hemisphere from the point source). Of course, every point on every slit to which the incident wave reaches plays as a point wave source for the diffraction wave and all these contributions to the diffraction wave determine the detailed diffraction wave light property distribution, but diffraction angles (at the grating) at which the diffraction wave intensity is highest are determined only by these quasi point sources corresponding the slits in the grating. After the incident light (wave) interacts with the grating, the resulting diffracted light from the grating is composed of the sum of interfering wave components emanating from each slit in the grating; At any given point in space through which the diffracted light may pass, typically called observation point, the path length from each slit in the grating to the given point varies, so the phase of the wave emanating from each of the slits at that point also varies. As a result, the sum of the diffracted waves from the grating slits at the given observation point creates a peak, valley, or some degree between them in light intensity through additive and destructive interference. When the difference between the light paths from adjacent slits to the observation point is equal to an odd integer-multiple of the half of the wavelength that is, equal to for integer the waves are out of phase at that point, and thus cancel each other to create the (locally) minimum light intensity. Similarly, when the path difference is a multiple of , the waves are in phase and the (locally) maximum intensity occurs. For light at the normal incidence to the grating, the intensity maxima occur at diffraction angles , which satisfy the relationship , where is the angle between the diffracted ray and the grating's normal vector, is the distance from the center of one slit to the center of the adjacent slit, and is an integer representing the propagation-mode of interest called the diffraction order.

When a plane light wave is normally incident on a grating of uniform period , the diffracted light has maxima at diffraction angles given by a special case of the grating equation as

It can be shown that if the plane wave is incident at angle relative to the grating normal, in the plane orthogonal to the grating periodicity, the grating equation becomes

which describes in-plane diffraction as a special case of the more general scenario of conical, or off-plane, diffraction described by the generalized grating equation:

where is the angle between the direction of the plane wave and the direction of the grating grooves, which is orthogonal to both the directions of grating periodicity and grating normal. Various sign conventions for , and are used; any choice is fine as long as the choice is kept through diffraction-related calculations. When solved for diffracted angle at which the diffracted wave intensity are maximized, the equation becomes

The diffracted light that corresponds to direct transmission for a transmissive diffraction grating or specular reflection for a reflective grating is called the zero order, and is denoted . The other diffracted light intensity maxima occur at angles represented by non-zero integer diffraction orders . Note that can be positive or negative, corresponding to diffracted orders on both sides of the zero-order diffracted beam.

Even if the grating equation is derived from a specific grating such as the grating in the right diagram (this grating is called a blazed grating), the equation can apply to any regular structure of the same spacing, because the phase relationship between light scattered from adjacent diffracting elements of the grating remains the same. The detailed diffracted light property distribution (e.g., intensity) depends on the detailed structure of the grating elements as well as on the number of elements in the grating, but it always gives maxima in the directions given by the grating equation.

Depending on how a grating modulates incident light on it to cause the diffracted light, there are the following grating types:

Transmission amplitude diffraction grating, which spatially and periodically modulates the intensity of an incident wave that transmits through the grating (and the diffracted wave is the consequence of this modulation). Reflection amplitude diffraction gratings, which spatially and periodically modulate the intensity of an incident wave that is reflected from the grating. Transmission phase diffraction grating, that spatially and periodically modulates the phase of an incident wave passing through the grating. Reflection phase diffraction grating, that spatially and periodically modulates the phase of an incident wave reflected from the grating.

An optical axis diffraction grating, in which the optical axis is spatially and periodically modulated, is also considered either a reflection or transmission phase diffraction grating.

The grating equation applies to all these gratings due to the same phase relationship between the diffracted waves from adjacent diffracting elements of the gratings, even if the detailed distribution of the diffracted wave property depends on the detailed structure of each grating.

Quantum electrodynamics

Quantum electrodynamics (QED) offers another derivation of the properties of a diffraction grating in terms of photons as particles (at some level). QED can be described intuitively with the path integral formulation of quantum mechanics. As such it can model photons as potentially following all paths from a source to a final point, each path with a certain probability amplitude. These probability amplitudes can be represented as a complex number or equivalent vector—or, as Richard Feynman simply calls them in his book on QED, "arrows".