How to Calculate Machine-Vision Lens Focal Length
Sometimes a lens gets picked by eyeballing the catalog. Try 25mm, and if that doesn’t work, switch to 16mm.
Focal length comes out of a calculation. There’s only one formula, and it needs just three values.
The Three Values the Calculation Needs
| Symbol | Name | Description |
|---|---|---|
| WD | Working distance | Distance from the front of the lens to the target (mm) |
| FOV | Field of view | The range that must be captured in one shot (mm) |
| Sensor size | Sensor size | Physical size of the camera sensor (mm) |
Once these three values are set, the focal length comes out automatically.
The Formula
f = Sensor size × WD / FOV
f is the focal length, and all units are in millimeters. The sensor dimension and the FOV dimension must match on the same axis — horizontal with horizontal, vertical with vertical.
Worked Example
Say you want to view a 100mm-wide range from a distance of 200mm. Assume the camera has a 1/2-inch sensor (6.4mm wide).
f = 6.4 × 200 / 100 = 12.8 mm
There’s no product that comes in exactly 12.8mm. In practice you have to choose between 12mm and 16mm. Which one you pick changes the field of view.
Sensor Size Table
Sensor format is notated in inches, but that notation has no direct relationship to the actual dimensions. You have to look them up.
| Format | Width (mm) | Height (mm) | Diagonal (mm) |
|---|---|---|---|
| 1/3″ | 4.8 | 3.6 | 6.0 |
| 1/2.5″ | 5.7 | 4.3 | 7.2 |
| 1/2″ | 6.4 | 4.8 | 8.0 |
| 1/1.8″ | 7.2 | 5.4 | 9.0 |
| 2/3″ | 8.8 | 6.6 | 11.0 |
| 1″ | 12.8 | 9.6 | 16.0 |
| 4/3″ | 17.3 | 13.0 | 21.6 |
These are commonly used values and can vary slightly by manufacturer. For an exact value, it’s safer to check the camera’s spec sheet.
Checking Resolution
Getting a focal length isn’t the end of it. You still have to confirm that combination can actually see the defect you’re after.
Resolution (mm/px) = FOV / horizontal pixel count
In the earlier example, if the camera is 1600×1200 pixels:
Resolution = 100 / 1600 = 0.0625 mm/px
Each pixel covers 0.0625mm. If the defect you need to detect is 0.1mm, that comes out to about 1.6 pixels.
That’s not enough. A single defect needs at least 3 pixels assigned to it to be caught reliably. In this case, you need to either narrow the field of view or switch to a higher-resolution camera.
Review Sequence
Putting it all together, the order is as follows.
| Step | Decision | Basis |
|---|---|---|
| 1 | Minimum defect size to detect | Inspection spec |
| 2 | Required resolution | 1/3 or less of the defect size |
| 3 | Field of view and pixel count | Back-calculated from resolution |
| 4 | Working distance | Equipment space constraints |
| 5 | Focal length | Calculated from the formula above |
| 6 | Actual product selection | Nearest available spec to the calculated value |
A product that exactly matches the calculated value almost never exists. Pick the nearest spec, then recalculate to confirm how the field of view changes as a result.
Things to Watch Out For
Don’t Mix Up Horizontal and Vertical
If you calculated using the sensor’s horizontal dimension, the FOV must also be horizontal. Calculating with the diagonal makes the actual field of view narrower than expected.
Check the Image Circle
Every lens has a fixed sensor size it can cover. Mount a lens designed for a 2/3-inch sensor onto a 1-inch sensor, and the four corners go dark.
Working Distance Has a Minimum
Every lens has a shortest distance at which it can still focus. If the calculated WD comes out shorter than that, the lens simply can’t focus at that distance.
The Calculation Is a Starting Point
The formula assumes an ideal, distortion-free lens. In practice, the image can wobble at the edges, or magnification can shift slightly. For precision dimensional measurement, a telecentric lens needs to be considered.
Closing
Calculating the focal length itself is one multiplication and one division. The hard part is balancing field of view, resolution, and working distance against each other.
Even so, starting from numbers gets you to an answer far faster than eyeballing it.
The formulas and figures in this article are general design guidance. Please check the lens and camera spec sheets before applying them in practice.
Related Reading — Machine-Vision Inspection: Physics Comes Before Software

