ForHosting KIT · Science

Diffraction grating calculator

Find the angle where a grating sends each bright order, or learn that the order cannot exist: with lines 0.000001667 m apart and light of 5.5 × 10⁻⁷ m, order 3 is the highest one reachable. Every arcsine step is shown. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Grating spacing d
0.000001667
Wavelength
0.00000055
Diffraction order m
1
You get
D
0.000001667
Lambda
0.00000055
M
1
Sin theta
0.3299340132

A diffraction grating calculator turns grating spacing, light wavelength, and diffraction order into the angle where that bright fringe appears. Enter positive spacing d and wavelength λ in any shared length unit, plus integer order m; the tool solves the grating equation d times sine of theta equals m times lambda, returns theta in radians and degrees, the sine value, the maximum reachable absolute order, and step-by-step substitution. Lab reports, spectroscopy homework, laser-alignment checks, and instrument design all need that same deterministic arcsin path without a full optics suite.

What the grating equation means for d, λ, and order m

A transmission or reflection diffraction grating has many parallel slits or ruled lines separated by a fixed spacing d. When monochromatic light of wavelength λ illuminates the grating at normal incidence, constructive interference appears at angles θ that satisfy the grating equation d times sine of theta equals m times lambda, where m is an integer called the diffraction order. The zero-order beam (m equals zero) travels straight ahead with theta equal to zero.

Positive and negative first, second, and higher orders fan out symmetrically on either side of that central beam. Because the absolute value of sine cannot exceed one, only orders with absolute m lambda over d less than or equal to one can exist for a given d and λ; larger orders are said to be unreachable or cut off.

Classroom and lab workflows care about that cutoff as much as the angle itself: a student who asks for third order when only first order is allowed has left the physical domain, and a silent clamp to ninety degrees would hide the mistake. This tool recomputes the sine ratio, rejects unreachable orders with a message that states the maximum absolute order as floor of d over λ, and on success ships rounded angles plus substitution steps you can assert in tests or lab notebooks.

Keep d and λ in the same length unit—metres, micrometres, or nanometres all work—because the ratio cancels the unit; mixing nanometres for wavelength with millimetres for spacing without conversion will produce nonsense ratios and false cutoffs.

Lab reports for single-wavelength grating experiments

Students enter measured d, laser λ, and observed order m to obtain θ in degrees and compare against protractor or camera measurements before writing the discussion section.

Homework checks for the grating equation

Teachers generate known-good first-order angles and deliberate oversize-m rejections so learners can verify hand-worked sinθ equals mλ/d steps.

What is the diffraction grating equation?

For normal incidence, d · sin(θ) = m · λ, where d is the spacing between adjacent lines, λ is the wavelength, m is the integer order, and θ is the diffraction angle from the forward direction.

When is an order unreachable?

When |m·λ/d| > 1, because |sin θ| cannot exceed 1.

What units should I use for d and λ?

Any shared length unit works (metres, micrometres, nanometres) because only the ratio m·λ/d appears. Do not mix units without converting.

Is the diffraction grating calculator free?

The browser tool is free and runs locally.

Can I enter a negative diffraction order?

Yes. A negative order is the matching bright fringe on the other side of the straight-through beam, at the same angle with the opposite sign. Order zero always comes out at an angle of zero.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/optics/diffraction-grating

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/optics/diffraction-grating \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spacing":0.000001667,"wavelength":5.5e-7,"order":1}'
{
  "spacing": 0.000001667,
  "wavelength": 5.5e-7,
  "order": 1
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "optics.diffraction_grating",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs1000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

When the requested order is physically unreachable—because the absolute value of m lambda over d exceeds one—the API returns a clear invalid_input error naming the maximum order instead of inventing an imaginary angle.

How to call the API and what comes back

Spacing and wavelength must be finite positive numbers within the published absolute limits; order must be an integer that may be negative for the opposite side of the zero-order beam. Send a JSON body with three required fields: spacing (aliases d, grating_spacing, slit_spacing, line_spacing), wavelength (aliases lambda, wl, wave_length), and order (aliases m, diffraction_order, n). Absolute values stay within the published ceilings so intermediate products remain finite in IEEE double precision on the Worker and in the browser. On success the response echoes rounded spacing, d, wavelength, lambda, order, and m; sets sin_theta to the clamped ratio m lambda over d; angle_rad and theta_rad to arcsin of that ratio in radians; angle_deg and theta_deg to the same angle in degrees; max_order_abs to the largest absolute integer order still allowed; side to zero_order, positive, or negative; formula to the string d · sin(θ) = m · λ; message to a short English summary; and steps to an ordered array of substitution lines. Failed validation—missing fields, non-finite or non-positive lengths, non-integer order, values outside absolute limits, or an unreachable order where absolute m lambda over d exceeds one—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price.

Practical tips, limits, and related searches

Convert ruled density into spacing before you call: if a grating is specified as N lines per millimetre, then d equals one over N in millimetres, or convert consistently into metres for SI reports. Prefer nanometres for visible laser lines only when spacing is also expressed in nanometres; otherwise convert both to metres so lab partners share one convention. Near-grazing orders where absolute sine is extremely close to one are accepted and reported near plus or minus ninety degrees after fixed rounding, matching the physical limit rather than rejecting float noise. Prefer this capability when you already have d, λ, and m and only need θ or a reachability check. Check max_order_abs first when scanning many orders in a script, and only request m values from negative max through positive max inclusive of zero. When teaching, pair examples: a five-hundred-nanometre line on a six-hundred-lines-per-millimetre grating with m equals one yields a clean mid-range angle; the same grating with a deliberately large m demonstrates the unreachable-order invalid_input path; and m equals zero always returns zero degrees. This landing targets people searching for a diffraction grating calculator, grating angle from spacing and wavelength, or order cutoff online; it is not a full spectrometer ray-tracer, not a multi-wavelength blaze-efficiency model, and not a tool that converts lines per millimetre for you without you computing d. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when learners deliberately request oversize orders. Round-trip checks are easy: recompute m times lambda over d by hand, confirm it equals published sin_theta within twelve-decimal rounding, and confirm that arcsin of that value matches angle_rad.

Spectrometer design order cutoffs

Instrument pipelines compute max_order_abs for each channel wavelength and reject configuration rows that request unreachable diffraction orders.

Does order zero return an angle?

Yes. m = 0 is the undiffracted zero-order beam with θ = 0° (and 0 rad).

Read the full KIT documentation →