ForHosting KIT · Home, food & hobbies

Depth of field calculator

A 50 mm lens at f/2.8 focused at 5 m keeps things sharp from just over 4 m to almost 6 m. See near limit, far limit, total zone and hyperfocal distance before you pick an aperture. 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
Focal length mm
50
Aperture as f-number N
2.8
Focus distance m
5
Circle of confusion mm
0.03
You get
Hyperfocal m
29.8119047619 m
Near m
4.2869881336
Far m
5.9975050379
Total m
1.7105169043

A depth of field calculator turns four photographic inputs into the near limit, far limit, and total zone of acceptable sharpness around your focus plane. Enter focal length in millimetres, aperture as an f-number, focus distance in metres, and the circle of confusion in millimetres for your sensor format; the tool returns hyperfocal distance plus near, far, and total depth of field in metres, with step-by-step substitution you can check by hand. Portrait, landscape, product, and macro shooters all need the same near-and-far numbers when choosing aperture and subject distance without opening a spreadsheet.

What depth of field means and how the formulas work

Depth of field is the distance range in front of and behind the focus plane where blur remains below a chosen circle of confusion. In the standard photographic model you need four positive numbers: focal length f in millimetres, aperture N as the dimensionless f-number, subject focus distance s in metres, and circle of confusion diameter c in millimetres.

The hyperfocal distance H equals f squared over N times c, plus f; when you focus at H, everything from roughly H over two to infinity is acceptably sharp for that c. For a general subject distance the near limit is s times (H minus f) divided by (H plus s minus two f), and the far limit is s times (H minus f) divided by (H minus s) whenever s is less than H.

When focus is at or beyond the hyperfocal distance the far limit becomes infinite and total depth of field is reported as infinite rather than a finite span. Smaller apertures (larger N), shorter focal lengths, and larger CoC values all widen the zone; longer glass, wider apertures, and tighter CoC values shrink it.

Teachers and camera clubs care about the non-positive distance rejection as much as the happy path: a zero-metre subject distance is not a valid photographic setup, and a silent clamp to a tiny epsilon would hide bad input. The check path recomputes hyperfocal, near, and far with the same fixed rounding used for published fields, so a successful response always ships with steps you can assert in tests or field notes.

Practical tips, sensor CoC choices, and related searches

Pick a circle of confusion that matches how you will view the image: about zero point zero three millimetres is a common full-frame print-oriented default; APS-C bodies often use roughly zero point zero one nine millimetres, and Micro Four Thirds smaller still. Keep focus distance in metres and focal length in millimetres so you do not mix units; the solver converts subject distance to millimetres internally before applying the hyperfocal formulas and converts results back to metres.

Prefer sending numbers rather than pre-formatted strings when you control the client; string numbers are accepted only when they match a strict finite numeric pattern. When teaching, pair examples: fifty millimetres at f slash two point eight focused at five metres with CoC zero point zero three yields a modest total DOF around the subject; eighty-five millimetres at f slash one point eight focused at two metres produces a thin portrait plane; and the same fifty millimetre lens focused far beyond hyperfocal demonstrates infinite far and null total.

This landing targets people searching for a depth of field calculator, DOF near far, hyperfocal distance, or aperture and focal length DOF online; it is not a diffraction blur estimator, not a bokeh simulator, and not a lens rental catalog. Prefer this capability when you already know f, N, s, and c and only need the near far total triple; if your source is a crop factor discussion, choose CoC for the sensor first.

Portrait aperture planning

Portrait shooters enter 85 mm, f/1.8, subject distance, and full-frame CoC to see how thin the sharp plane is before choosing a stop down.

Landscape hyperfocal checks

Landscape photographers compare near and far limits at f/8 or f/11 against hyperfocal so foreground rocks and distant ridges stay acceptably sharp.

What inputs does the depth of field calculator need?

Four positive numbers: focal length in mm, aperture as f-number, focus distance in metres, and circle of confusion in mm. It returns near, far, total DOF, and hyperfocal distance.

What happens if focus distance is zero or negative?

Focus distance and the other optical lengths must be strictly positive.

Which circle of confusion should I use?

A common full-frame default is 0.03 mm. APS-C often uses about 0.019 mm; pick the value that matches your sensor and viewing criteria.

Is the depth of field calculator free?

The browser tool is free and runs locally.

When does depth of field extend to infinity?

When you focus at or beyond the hyperfocal distance, the far limit becomes infinite. Focus exactly at that distance and everything from about half of it to the horizon stays acceptably sharp for your circle of confusion.

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/hobby/depth-of-field

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/hobby/depth-of-field \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"focal_length_mm":50,"aperture":2.8,"focus_distance_m":5,"circle_of_confusion_mm":0.03}'
{
  "focal_length_mm": 50,
  "aperture": 2.8,
  "focus_distance_m": 5,
  "circle_of_confusion_mm": 0.03
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "hobby.depth_of_field",
  "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.

Zero or negative focus distance is rejected with a clear invalid_input error, because distance in the thin-lens DOF model must be strictly positive.

How to call the API and what comes back

Every length-like field must be strictly positive; values at or below one times ten to the minus fifteen are treated as non-positive and rejected, which covers the required zero and negative focus-distance errors. Send a JSON body with four required finite positive numbers: focal_length_mm (aliases focal_length, f, focal_mm, focal), aperture (aliases f_number, fstop, f_stop, N, f_n), focus_distance_m (aliases focus_distance, distance, subject_distance, s, distance_m), and circle_of_confusion_mm (aliases coc, coc_mm, circle_of_confusion, c). Absolute values must stay within the published limit of one trillion so intermediate products remain finite in IEEE double precision on the Worker and in the browser. On success the response echoes rounded inputs, sets hyperfocal_m to the hyperfocal distance in metres, near_m far_m and total_m to the DOF limits in metres, far_infinite to true when the far limit is infinite, unit to the string m, formula to a compact summary of the equations, message to a short English summary, and steps to an ordered array of substitution lines. When far is infinite, far_m and total_m are null and far_infinite is true so clients never rely on non-JSON Infinity values. Failed validation—missing fields, non-finite numbers, values outside absolute limits, or non-positive distances—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, sensor CoC choices, and related searches

Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when learners deliberately set focus distance to zero. Round-trip checks are easy: recompute H equals f squared over N c plus f by hand and confirm near and far match the published metres within the same twelve-decimal rounding, and confirm that moving focus past hyperfocal flips far_infinite to true with null far_m and total_m.

Unit tests for camera apps

Mobile camera and education apps generate known-good DOF triples and deliberate zero-distance rejections for deterministic regression fixtures.

When is the far limit infinite?

When focus distance is at or beyond the hyperfocal distance. far_m and total_m are null and far_infinite is true.

Read the full KIT documentation →