Distance Calculator

Compute the straight-line distance between two points in 2D or 3D: with the formula, substitution, and midpoint shown.

Details

Flat or 3D?

Your points

A
B

Distance between the points

5

From A to B

How far across (x)3
How far up (y)4
Point halfway between(1.5, 2)

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.

From (2, 3) to (8, 7)
8 − 2 = 6horizontal gap
7 − 3 = 4vertical gap
√(6² + 4²)Pythagoras on those two
=
7.21the distance

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.

d = √( (x₂−x₁)² + (y₂−y₁)² )
(x₂−x₁)
The horizontal gap
(y₂−y₁)
The vertical gap
Undoes the squaring, returning a length
  1. Subtract the x values. 8 − 2 = 6. This is how far across the points are.

  2. Subtract the y values. 7 − 3 = 4. This is how far apart vertically.

  3. Square both and add. 36 + 16 = 52. Squaring removes any negative signs automatically.

  4. 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

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