Diffraction Grating Calculator

Use this diffraction grating calculator to solve for diffraction angle, wavelength, grating spacing, or line density for any diffraction order, including non-normal incidence. It also checks which orders are physically possible so you can catch unit and setup mistakes fast.

Advanced options
Units and sign convention
Angle input (only when needed)
Compute multiple orders (optional)
Calculating…
Did we solve your problem today?

How to use our Diffraction Grating Calculator

  1. Choose what to solve for in "Solve for" (diffraction angle, wavelength, spacing, or line density).
  2. Enter your wavelength (pick a unit in Advanced options if you are not using nm).
  3. Enter the grating as either line density (lines/mm) or spacing d (micrometers) in Advanced options.
  4. Enter the diffraction order m (an integer like 0, 1, 2). If you are solving for wavelength or grating values, do not use m = 0.
  5. Enter the angle of incidence (degrees), measured from the grating normal (perpendicular line).
  6. If needed, enter the diffraction angle theta m (degrees) in Advanced options (only required when you are solving for wavelength or the grating).
  7. In Advanced options, pick the "Angle convention" that matches your class diagram so the signs come out right.
  8. Optional: switch to "Orders output mode" = range, then set m min and m max to list several orders at once.
  9. Click Calculate and read the feasibility note and the maximum possible order magnitude to see which orders can exist.

Definitions

Diffraction grating: A surface with many evenly spaced lines (grooves or slits) that spreads light into different directions by interference.[1]

Grating spacing (d): The distance between adjacent lines. Smaller d means more lines per millimeter.[2]

Line density: How many lines there are per millimeter (lines/mm). It is the reciprocal of spacing after unit conversion.[3]

Wavelength (lambda): The distance between wave peaks (for light, it sets the color).

Diffraction order (m): The bright-spot index (0 is the central maximum, 1 is first order, 2 is second order, etc.).[2]

Angle of incidence (theta i): The incoming beam angle measured from the grating normal (a line perpendicular to the grating).[4]

Diffraction angle (theta m): The outgoing beam angle (for order m) measured from the grating normal.[2]

Feasible order: An order that gives a real angle, meaning the computed sine value stays between -1 and 1.


Methodology

1) Units and angle handling

Angles are entered in degrees and converted to radians for trig calculations.

radians = degrees * (pi/180)

Wavelength is converted to meters based on the selected unit, and spacing d is converted to meters if entered in micrometers.

lambda_m = { nm: wavelength*1e-9, um: wavelength*1e-6, mm: wavelength*1e-3, m: wavelength }

d_m = spacing_um * 1e-6

2) Convert line density to spacing (if needed)

If you enter line density in lines/mm, the calculator converts it to lines/m and then computes spacing.

sigma_lines_per_m = line_density_lines_per_mm * 1000

d_m = 1 / sigma_lines_per_m

This matches the standard relationship between line density and spacing.[3]

3) Choose an angle sign convention

Different diagrams measure angles on different sides of the normal. This calculator lets you choose a convention so the rearranged equation matches your setup.[2]

Plus-sign convention (common in student diagrams)

m * lambda = d * (sin(theta_m) + sin(theta_i))

sin(theta_m) = (m*lambda/d) - sin(theta_i)

Minus-sign convention (common in some optics references)

m * lambda = d * (sin(theta_i) - sin(theta_m))

sin(theta_m) = sin(theta_i) - (m*lambda/d)

If you set incidence angle to 0 degrees, the plus-sign convention reduces to the normal-incidence form.[2]

m * lambda = d * sin(theta_m) (when theta_i = 0)

4) Solving for the selected unknown

Solve for diffraction angle: compute sin(theta_m) from the chosen convention, then take arcsin to get theta_m. If the sine value is outside [-1, 1], that order is not physically possible.

theta_m = arcsin( sin(theta_m) )

Solve for wavelength: requires m not equal to 0 (because m = 0 always gives the central maximum and does not determine lambda from angles).

lambda = (d / m) * (sin(theta_m) + sin(theta_i)) (plus-sign)

lambda = (d / m) * (sin(theta_i) - sin(theta_m)) (minus-sign)

Solve for spacing d: rearrange the chosen convention (also requires m not equal to 0).

d = (m * lambda) / (sin(theta_m) + sin(theta_i)) (plus-sign)

d = (m * lambda) / (sin(theta_i) - sin(theta_m)) (minus-sign)

Solve for line density: first solve for spacing d, then convert to lines/mm.

line_density_lines_per_mm = (1/d_m) / 1000

5) Feasibility (impossible orders) and tiny rounding tolerance

The calculator checks whether a real angle exists using the sine range rule.[2]

-1 <= sin(theta_m) <= 1

If the computed sine is only barely outside the range due to floating-point rounding (within 1e-12), it is clamped into the range before arcsin. Otherwise the output is marked N/A and the feasibility note explains that the requested order cannot occur for that setup.

6) Maximum possible order magnitude

For the plus-sign convention only, the calculator estimates the largest order magnitude that could exist given the incidence angle, using the requirement sin(theta_m) <= 1.

|m|max = floor( (d/lambda) * (1 + sin(theta_i)) )

This is a quick feasibility check students can use to avoid asking for an order that cannot exist.[2]

For the minus-sign convention, |m|max depends on the chosen direction/sign of orders in your setup, so the calculator reports N/A instead of guessing.

7) Order range table

If you choose range mode, the calculator loops through each integer m from m min to m max and computes theta_m for each. Any order that fails the feasibility check is shown as N/A so you can see which bright spots exist.


Sources