How to use the Distance Formula
- Enter the first point's x₁ and y₁, adding z₁ only if you are working in three dimensions.
- Enter the second point the same way.
- Leave both z values at zero for a purely two-dimensional problem.
- Read the 2D distance for a flat plan, or the 3D distance when height differences matter.
- Use the Manhattan figure when movement is restricted to axis-aligned steps.
How the calculation works
The distance formula is the Pythagorean theorem applied to coordinate differences. The horizontal and vertical gaps between two points form the legs of a right triangle whose hypotenuse is the direct distance, giving √((x₂−x₁)² + (y₂−y₁)²). Extending to three dimensions adds the z difference under the same square root, because the 3D case is just the 2D result used as a leg of a second right triangle.
The implementation uses the hypot function rather than raw squaring and adding. Squaring very large coordinates can overflow to infinity and squaring very small ones can underflow to zero, both of which destroy the answer; hypot scales the inputs internally to avoid that. For everyday coordinate values the two approaches agree exactly, but the safer routine costs nothing.
Manhattan distance — the sum of absolute coordinate differences — answers a different question: how far you must travel when diagonal movement is forbidden. It is the right metric for city blocks laid out on a grid, for warehouse aisle routing, for circuit-board trace lengths and for chess-like game movement. It is always at least as large as the straight-line distance, and can be up to √2 times larger in two dimensions.
d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²); Manhattan = |x₂−x₁| + |y₂−y₁| + |z₂−z₁|Source: Euclidean metric derived from the Pythagorean theorem; Manhattan (taxicab) metric per Krause, Taxicab Geometry (1975).
Worked example
A drone flies from a launch pad at (120, 45, 0) to a rooftop sensor at (260, 175, 38), in metres.
- Differences: Δx = 140, Δy = 130, Δz = 38.
- Ground distance: √(140² + 130²) = √(19600 + 16900) = 191.05 m.
- 3D distance: √(19600 + 16900 + 1444) = √37944 = 194.79 m.
- Manhattan: 140 + 130 + 38 = 308 m.
194.79 m direct flight against 308 m if the drone were restricted to axis-aligned legs — a 58% penalty for grid-constrained routing.
Frequently asked questions
Does this work for latitude and longitude?+
No. Degrees of longitude shrink towards the poles, so treating them as flat coordinates overstates east-west distance. Great-circle (haversine) distance is required for geographic points.
Why is Manhattan distance ever preferred?+
Because it reflects the actual constrained path. Straight-line distance between two street addresses is a lower bound nobody can drive.
Do the units matter?+
Only that they are consistent. Feed in metres and you get metres out; mixing metres and feet produces nonsense.
What if the two points are the same?+
Every difference is zero, so the distance is zero. That is correct, not an error.
Last reviewed August 31, 2026. We review this page whenever the underlying formula, tax year, published rate or standard changes.