Diffraction Grating Calculator – Angle for Each Order d sinθ = mλ

Use this free Diffraction Grating Calculator to find the angle at which a grating sends light of a given wavelength for any order of the spectrum — the tool behind spectroscopes and CD rainbow effects.

A diffraction grating is a surface ruled with thousands of evenly spaced lines — hundreds or thousands per millimetre — and it is the most precise wavelength-measuring device in all of optics. Shine light through it (or reflect light off it) and the waves emerging from every line interfere: in most directions they cancel, but in a few special directions they reinforce perfectly, and a bright beam leaves at an angle fixed by one compact equation, d sinθ = mλ. Measure the angle, and you have measured the wavelength — to several decimal places, with a ruler and a protractor.

Those special directions are called orders, numbered m = 0, 1, 2, 3… The zeroth order is no spectrum at all: the light goes straight through, all colours together. Each higher order is a complete spectrum, fanned wider and stretched thinner than the one before, with red always deflected more than blue — the opposite of a prism. Because the spacing d is comparable to the wavelength itself, the angles are large and exquisitely sensitive to λ, which is why gratings, not prisms, sit at the heart of professional spectroscopes.

Diffraction Grating Calculator — formula and diagram

The numbers on this page are the working numbers of spectroscopy: a school grating of 300–600 lines per millimetre, a CD's accidental grating of about 625, research gratings of 1,200 and beyond. The sections below explain why the maxima are so sharp, why some orders cannot exist, how astronomers read the composition of stars from grating spectra, and how to turn the calculator into a wavelength meter for an unknown source.

m = 0 m = 1 m = 2 grating light in

Formula

d sinθ = mλ, so θ = sin−1(mλ / d)  •  θ is measured from the straight-ahead direction (the normal to the grating)

The spacing d is set by the ruling density: d = 1 ÷ (lines per metre), or in handy units, d in nanometres = 1,000,000 ÷ (lines per mm). A grating with 500 lines/mm has d = 2000 nm. Since sinθ can never exceed 1, the largest order that can exist is mmax = d ÷ λ, rounded down — a hard ceiling this calculator enforces for you. Rearranged, the equation is also a measuring instrument: λ = d sinθ ÷ m, the form spectroscopists use to identify unknown light.

SymbolMeaningUnits
dspacing between neighbouring linesm or nm
θangle of the m-th order maximum, from the normaldegrees
morder of the spectrum (0, 1, 2, …)no units
λwavelength of the lightm or nm
lines/mmruling density printed on the gratingper millimetre

Why thousands of lines make razor-sharp maxima

Picture two neighbouring lines of the grating as two slits. Light leaving them at angle θ travels different distances, and the extra distance for the farther slit is exactly d sinθ. When that path difference equals a whole number of wavelengths, the two waves arrive in step and reinforce. With only two slits, "roughly in step" covers a wide range of angles, so double-slit fringes are broad. Now add thousands more lines. Every additional slit contributes a wave that must also arrive in step; tilt the angle slightly and the small mismatches accumulate from slit to slit until, across the whole grating, the waves cancel almost perfectly. The maximum survives only in a needle-thin range of angles around the exact d sinθ = mλ solution.

That sharpness is the grating's superpower. Broad fringes locate a wavelength approximately; needle-thin maxima locate it to one part in tens of thousands, and they separate two wavelengths that differ by a hair — the resolving power in the depth section below quantifies this. It is the same interference as the double slit, industrialised: where Young used two openings, the grating uses ten thousand, and trades brightness for precision.

The zeroth order deserves its reputation as the useless one. At θ = 0 the path difference is zero for every wavelength simultaneously, so all colours reinforce together and no spectrum forms — the grating behaves like plain glass. All the analysis happens in orders 1, 2 and 3, fanned symmetrically on both sides of the straight-through beam, each a mirror image of the other.

extra path = d sinθ = mλ two neighbouring lines, spacing d θ

How to use

  1. Enter the grating's line density in lines per millimetre — it is printed on the grating's frame or box (300, 500 and 600 are the common school values).
  2. Enter the wavelength of the light in nanometres (650 for a red laser pointer, 589 for a sodium lamp, 532 for a green laser).
  3. Enter the order m you want: 1 for the first spectrum out from the centre, 2 for the next, and so on. Order 0 is always at 0°.
  4. Click "Calculate Angle" to get the diffraction angle from the straight-ahead direction. The same spectrum appears at the same angle on the other side.
  5. If the calculator says the order does not exist, mλ has exceeded d — drop to a lower order or use a finer grating.

Worked examples

Example 1 — first order, and how many orders exist. A grating with 500 lines/mm is lit by orange light of wavelength 600 nm. The line spacing is d = 2000 nm.
For the first order (m = 1): sinθ = (1 × 600) ÷ 2000 = 0.300
θ = sin−1(0.300) = 17.46°.
The highest order that can exist is m = 2000 ÷ 600 = 3.33, so orders up to m = 3 appear.

Example 2 — the sodium doublet's home. A 600 lines/mm grating (d = 1667 nm) under sodium light, λ = 589 nm.
m = 1: sinθ = 589 ÷ 1667 = 0.353, θ = 20.70°.
m = 2: sinθ = 0.707, θ = 44.98°. No third order exists (3 × 589 > 1667) — mmax = 2. Sodium's yellow is actually two lines, 589.0 and 589.6 nm; separating them is the resolving-power challenge taken up below.

Example 3 — a coarse grating, many orders. 300 lines/mm (d = 3333 nm), green light λ = 500 nm.
m = 1: sinθ = 500 ÷ 3333 = 0.150, θ = 8.63°. The ceiling is generous here: mmax = 3333 ÷ 500 = 6, so six full spectra fan out on each side — the sixth order sits at sinθ = 0.900, θ = 64.16°. Coarse gratings trade spread for order count.

Example 4 — a CD as a grating. A CD's track pitch makes about 625 lines/mm (d = 1600 nm).
Red light (650 nm): sinθ = 650 ÷ 1600 = 0.406, θ = 23.97°.
Blue light (450 nm): sinθ = 450 ÷ 1600 = 0.281, θ = 16.33°.
The 7.6° gap between red and blue is the rainbow sheen you see when you tilt a disc under a lamp.

Example 5 — a fine grating squeezes the orders. 1000 lines/mm (d = 1000 nm), violet light λ = 400 nm.
m = 1: sinθ = 0.400, θ = 23.58°. m = 2: sinθ = 0.800, θ = 53.13°. m = 3 would need sinθ = 1.20 — impossible, so this grating shows violet in just two orders, each widely and cleanly spread.

Example 6 — the reddest light, the finest common grating. 1200 lines/mm (d = 833 nm), deep red λ = 700 nm.
sinθ = 700 ÷ 833 = 0.840, θ = 57.14° — and that is the only order, since 2 × 700 > 833. Long wavelengths on fine gratings live dangerously close to the 90° cliff edge where orders cease to exist.

Diffraction gratings in real life

Reading the stars. Every element in a star imprints dark or bright lines at its own exact wavelengths. A grating spectrograph spreads starlight into thousands of needle-thin maxima, and astronomers read off composition, temperature, rotation and — from tiny shifts of the lines — the star's radial velocity and the expansion of the universe itself.

Chemistry's fingerprints. Heat a chemical in a flame or discharge tube and it emits only its characteristic wavelengths. Grating spectrometers identify elements and measure concentrations from those lines — the technique that discovered helium in the Sun's spectrum (1868) before it was ever found on Earth.

Discs: CD, DVD, Blu-ray. The spiral data track is a ready-made reflection grating: pitch 1.6 µm on a CD (≈ 625 lines/mm), 0.74 µm on a DVD (≈ 1,350 lines/mm), 0.32 µm on a Blu-ray (≈ 3,125 lines/mm). The finer the track, the more violently the disc rainbows — a grating-density league table you can hold in your hand.

Monochromators and laser labs. Rotate a grating and the angle condition selects one wavelength at a time from a broad source — a monochromator, the wavelength tap of experimental optics. The same principle, run in reverse inside tunable lasers, picks the laser's exact operating colour.

Fibre-optic telecommunications. Dozens of wavelength channels share one fibre, and grating-based multiplexers split them apart at the receiving end by sending each colour to its own angle — the d sinθ = mλ equation routing internet traffic.

X-ray crystallography's cousin. A crystal's atomic planes, spaced by fractions of a nanometre, diffract X-rays by the same path-difference logic (Bragg's law is the grating equation in a mirror). The double helix was measured this way: nature's own grating, read with nature's shortest light.

white light in violet red — bent most grating

Resolving power: R = mN

How close can two wavelengths be before their maxima blur into one? A grating's resolving power is R = λ ÷ Δλ = m × N, where N is the total number of lines illuminated. Sodium's doublet — 589.0 and 589.6 nm — demands R ≈ 589 ÷ 0.6 ≈ 982: in second order, a mere 500 illuminated lines would do it in principle. A research grating 25 mm wide at 600 lines/mm puts N = 15,000 lines to work; in second order R = 30,000, separating lines just 0.02 nm apart at 589 nm. Note what R does not depend on: the spacing alone. A coarse grating lit across a wide beam can out-resolve a fine one lit narrowly — it is the total count of cooperating waves that sharpens the line.

Overlapping orders: the grating's one untidiness

The equation d sinθ = mλ has an ambiguity: the product mλ is all that matters. Second-order light of 300 nm (ultraviolet) lands at exactly the angle of first-order 600 nm (orange), because 2 × 300 = 1 × 600 = 600. In a spectrum spanning more than an octave, orders pile on top of each other, and the instrument must filter out the interlopers — glass that absorbs the ultraviolet, or a small prism crossed with the grating to sort the orders sideways. It is the price of the equation's beautiful simplicity: it sorts by mλ, and trusts you to know which m you are looking at.

Transmission or reflection — the same equation

Gratings come in two mechanical forms: transparent plates the light passes through, and mirror-like plates it reflects off. The calculator's equation serves both, because the physics is identical — an array of equally spaced sources whose path differences must equal whole wavelengths. Reflection gratings dominate research instruments (they work in the ultraviolet, where glass absorbs, and lose no light to a substrate), while the transmission form survives in school benches and in the rainbow film sold for science toys. A CD is a reflection grating; the plastic replica in a textbook kit is a transmission grating; tilting either under a lamp demonstrates the same d sinθ = mλ.

Quick reference: ruling density and spacing

GratingLine spacing d
100 lines/mm10,000 nm
300 lines/mm3,333 nm
500 lines/mm2,000 nm
600 lines/mm1,667 nm
625 lines/mm (CD)1,600 nm
1,000 lines/mm1,000 nm
1,200 lines/mm833 nm
1,350 lines/mm (DVD)740 nm

Set the spacing beside the wavelength you are studying and the character of the grating is obvious: when d is barely twice λ, only one or two orders survive but they are spread across huge angles; when d is ten times λ, orders crowd together near the centre, fine in number and cramped in spread.

Common mistakes

  • Using the lines-per-mm figure as d. The equation wants the spacing, the reciprocal of the density. Feeding 500 into the formula as if it were d (instead of converting to 2000 nm) produces angles that are not just wrong but impossible — sinθ in the hundreds.
  • Mixing nanometres and millimetres. λ and d must share units before dividing. 600 nm against d = 0.002 mm is fine (600 ÷ 2,000,000 in metres, or 600 ÷ 2000 in nm) — the ratio is unitless, but only if both sides were converted the same way.
  • Expecting the zeroth order to show a spectrum. At m = 0 every wavelength sits at θ = 0, overlapped. Students hunt for colours in the brightest beam and find none; the spectra are the fainter beams to either side.
  • Measuring θ from the grating surface. The angle in d sinθ is measured from the normal — the straight-ahead direction — not from the grating's plane. Using the surface angle substitutes cosθ for sinθ and quietly wrecks the wavelength.
  • Asking for an order that cannot exist. If mλ > d, there is no angle. The calculator refuses; in the lab, the symptom is a spectrum that simply stops — a sign to use a coarser grating or a lower order, not to search harder.

FAQ

Why does a grating spread white light into colours?
The angle depends on the wavelength: red light (long λ) is deflected more than blue light (short λ). Each order is therefore a full little spectrum, which is exactly what a spectroscope uses to analyse light from stars and chemicals.

Why do some orders go missing?
If mλ/d is greater than 1, sinθ would have to exceed 1, which is impossible — that order simply does not exist. Finer gratings (smaller d) show fewer, more widely spread orders.

Is a CD or DVD a diffraction grating?
Yes! The spiral track acts like thousands of tiny lines (about 625 lines/mm on a CD). That is why white light reflecting off a disc breaks into rainbow colours at particular angles.

How is a grating different from a prism?
Both spread white light, but by opposite rules. A prism bends blue most (dispersion grows toward short wavelengths); a grating bends red most, because θ grows with λ. Grating spectra are also spread almost evenly by wavelength, while prism spectra crowd the red end — one reason spectroscopists prefer gratings for measurement.

Can I measure an unknown wavelength with this calculator?
Yes — that is its laboratory purpose. Measure the angle of a line in a known order, then λ = d sinθ ÷ m. With a 600 lines/mm grating, a first-order line at 20.70° gives λ = 1667 × sin(20.70°) = 589 nm: sodium, identified from one angle.

Why are the spectra on both sides identical?
The equation depends on the angle's sine, and the geometry is symmetric: tilt either way and the path differences work out the same. A grating produces two mirror-image sets of orders, left and right — handy when one side is blocked by the lamp housing.

What does "blazed" mean on a research grating?
A plain grating wastes much of its light in the useless zeroth order. Blazing angles the facets of each groove like tiny mirrors, steering most of the light into one chosen order on one side. Blazed gratings are far brighter where it counts — the spectrum you actually measure.

Does the light have to arrive head-on?
The simple formula assumes normal incidence — light arriving perpendicular to the grating. Tilt the incoming beam and the equation gains a term (d(sinθᵢ + sinθ) = mλ). Bench spectrometers are aligned for normal incidence precisely so this calculator's form applies.

Why do finer gratings show fewer orders?
Because mmax = d ÷ λ and finer means smaller d. A 1200 lines/mm grating (d = 833 nm) can show red light (700 nm) only in first order, while a 300 lines/mm grating shows it in four. Fewer orders, but each is spread across a much wider angle.

What are "ghost" lines in a grating spectrum?
Faint false lines caused by tiny periodic errors in the ruling engine that cut the grating — a second, unintended periodicity superimposes its own faint spectrum. Modern holographic gratings, made by interference itself rather than by a screw-driven engine, are essentially ghost-free.

David Okafor

David Okafor

Physics Writer · Waves & Light

David Okafor creates and reviews our waves, sound and optics calculators at CalcVIP. Every calculator is checked against hand-worked examples before it is published, so the formula, the diagram and the answer all agree.

View full profile & all calculators by Okafor →