Home / Math / Distance Calculator
Distance Calculator: Distance Between Two Points (2D and 3D)
Enter two points on a plane or in space and get the straight-line (Euclidean) distance between them, the coordinate differences, the squared distance and the taxicab distance for comparison.
The distance formula
The distance formula is the Pythagorean theorem applied to coordinates. Draw a right triangle whose hypotenuse is the segment between your two points. The horizontal leg has length |x2 − x1|, the vertical leg has length |y2 − y1|, and the hypotenuse is the distance:
d = √((x2 − x1)² + (y2 − y1)²)
In three dimensions the same idea adds a third term for depth or height:
d = √((x2 − x1)² + (y2 − y1)² + (z2 − z1)²)
Squaring removes the sign of each difference, so the order of the points never matters and negative coordinates cause no trouble.
Worked checks you can do in your head
The classic 3-4-5 triangle gives a clean test. From (0, 0) to (3, 4) the differences are 3 and 4, the squares sum to 25, and the distance is 5. In three dimensions, the differences 3, 4 and 12 give squares 9, 16 and 144, a sum of 169, and a distance of 13. If you see whole-number results for whole-number inputs like these, the formula is being applied correctly. Most other inputs produce an irrational distance, which the calculator rounds for display to at most four decimal places.
Straight-line versus taxicab distance
The straight-line distance is the shortest path between two points. The taxicab or Manhattan distance, |dx| + |dy| (+ |dz|), is the length of a path that may only move along the axes, like a delivery route on a street grid. It is always at least as large as the straight-line value and equals it only when the points share a row or column. The page shows both so you can see how much longer a grid route is than the direct line.
Common mistakes and limits
- Adding the square roots separately. The root is taken once, after summing the squares.
√9 + √16is 7, but√(9 + 16)is 5. - Mixing units. All coordinates must use the same unit. The answer then comes out in that unit.
- Using it for locations on Earth. Latitude and longitude describe a curved surface, so this flat formula becomes inaccurate over longer distances. Great-circle formulas are the right tool for that job.
- Comparing distances. When you only need to know which of two distances is larger, comparing the squared distances gives the same answer without computing a root. The calculator shows the squared total for this reason.
Worked example
Find the distance between the points (−2, 1, 3) and (4, −3, 6) in three-dimensional space.
Inputs
| Dimensions | 3D (x, y, z) |
|---|---|
| Point 1: x1 | -2 |
| Point 1: y1 | 1 |
| Point 1: z1 | 3 |
| Point 2: x2 | 4 |
| Point 2: y2 | -3 |
| Point 2: z2 | 6 |
Result
Straight-line distance in three dimensions.
| Difference in x | 6 |
|---|---|
| Difference in y | -4 |
| Difference in z | 3 |
| Sum of squared differences | 61 |
| Working | d = √(36 + 16 + 9) = √61 |
| Taxicab (Manhattan) distance | 13 |
| Midpoint | (1, -1, 4.5) |
Accuracy note: Results use standard double-precision arithmetic, so very large or very small values may be rounded. Check important results by another method.
Frequently asked questions
How do you find the distance between two points?
Subtract the x values, subtract the y values, square both differences, add the squares and take the square root of the sum. For (1, 2) and (4, 6) that is √(9 + 16) = 5.
What is the distance formula in 3D?
Add a third squared difference for the z coordinates under the same square root. The result is the straight-line length between two points in space.
Does the order of the points matter?
No. Each difference is squared, so swapping the points only changes signs before squaring and the final distance stays exactly the same.
Can the distance be negative?
No. A distance is a square root of a sum of squares, so it is zero or positive. It is zero only when both points are identical.
What is the difference between Euclidean and Manhattan distance?
Euclidean distance is the straight-line length, while Manhattan distance adds the absolute differences along each axis, as if you could only travel along a street grid.
Related calculators
References and sources
- Euclidean distance as a consequence of the Pythagorean theorem, in standard coordinate geometry and linear algebra texts.