Distance Calculator
Compute the straight-line distance between two points in 2D or 3D: with the formula, substitution, and midpoint shown.
Details
Your points
Distance between the points
5
From A to B
This works out the straight-line distance between two points on a coordinate grid, in two or three dimensions.
It also returns the midpoint and the horizontal and vertical gaps. For driving distance between towns you want a mapping service instead, since this measures pure geometry.
How distance between points is measured
The distance between two points is the length of the straight line joining them, and it comes from a right-angled triangle you may not have noticed was there.
Take the horizontal gap and the vertical gap between the points. Those two are the short sides of a right triangle, and the distance you want is its hypotenuse.
So the distance formula is not a new idea to memorise. It is Pythagoras applied to coordinates, which is why it looks the way it does.
Both gaps get squared, so their signs stop mattering. That is why the order you take the points in makes no difference to the answer.
What to enter
- Flat or 3D?
- Two dimensions for a flat grid, three when depth is involved. The method is identical; 3D just adds one more term.
- Coordinates
- The x, y and optionally z of each point. Order does not matter.
- Number of steps
- Divides the line into equal parts, giving the coordinates along the way.
What this assumes
The grid is flat. Distances between places on the globe follow a curved surface and need a different calculation.
This is straight-line distance. It ignores roads, obstacles and terrain entirely.
How to calculate the distance between two points
Find the gap on each axis, square them, add, and take the square root.
- (x₂−x₁)
- The horizontal gap
- (y₂−y₁)
- The vertical gap
- √
- Undoes the squaring, returning a length
Subtract the x values. 8 − 2 = 6. This is how far across the points are.
Subtract the y values. 7 − 3 = 4. This is how far apart vertically.
Square both and add. 36 + 16 = 52. Squaring removes any negative signs automatically.
Take the square root. √52 = 7.21. For 3D, add the squared z gap before rooting.
See a worked example: a 3D distance that comes out exactly whole
- First point
- (0, 0, 0)
- Second point
- (2, 3, 6)
Gaps: 2 across, 3 up, 6 deep.
Square each: 4, 9, 36.
Add them: 4 + 9 + 36 = 49.
√49 = 7 exactly. Whole-number 3D distances like this are rare, which is why 2-3-6 turns up so often in textbooks.
Exactly 7
Frequently asked questions
No. Both gaps are squared, and squaring makes any negative positive, so reversing the points gives the same distance.
This differs from slope, where the order genuinely matters because nothing is squared and the sign survives.
Exactly the same, with one extra term: d = √(Δx² + Δy² + Δz²).
The pattern continues into any number of dimensions. Each axis contributes its squared gap, which is why the formula scales so cleanly.
Not accurately. This measures straight lines on a flat grid, and the Earth is curved.
Distance between latitude and longitude points needs the haversine formula, which accounts for that curvature. And for driving distance you want a mapping service, since roads are never straight lines.
Because a negative times a negative is positive. A gap of −4 squares to 16, exactly as +4 does.
That is deliberate. Distance has no direction, so the formula is built to discard it.
The distance you would travel following a grid of streets rather than cutting straight across: simply |Δx| + |Δy|.
For (2,3) to (8,7) that is 6 + 4 = 10, against a straight-line distance of 7.21. It is used in city routing and in some machine-learning algorithms.
Problems people actually run into
Adding the gaps instead of squaring them
Going 6 across and 4 up does not mean travelling 10. The direct route is 7.21, and the difference is the whole point of the formula.
Adding them gives the grid-following distance rather than the straight line. Both are legitimate measures, but they answer different questions.
Forgetting the square root
Stopping at 52 leaves you with the distance squared, not the distance. It is an easy step to lose when the arithmetic before it felt like the hard part.
The sanity check: the answer should be a bit larger than the longer of the two gaps, and always smaller than their sum.
Results are estimates for general information only and are not professional financial, medical, or legal advice. Read our full disclaimer.
Last updated: September 4, 2026