How to use the distance formula calculator
- Pick 2D for points on a flat plane or 3D for points in space.
- Under Point A, enter x₁ and y₁ (and z₁ in 3D). Under Point B, enter x₂ and y₂ (and z₂ in 3D). Negatives and decimals are fine.
- Choose how many Decimal places to round to. The default is 4.
- Read the distance at the top of the result. The lines under it show each step. Swap A and B flips the two points.
The distance formula and where it comes from
In a plane, the distance between (x₁, y₁) and (x₂, y₂) is d = √((x₂ - x₁)² + (y₂ - y₁)²). In three dimensions you add one more term under the root: d = √((x₂ - x₁)² + (y₂ - y₁)² + (z₂ - z₁)²).
It is the Pythagorean theorem in disguise. The horizontal gap Δx and the vertical gap Δy are the two legs of a right triangle, and the straight line between the points is the hypotenuse. If you already know the legs, the Pythagorean theorem calculator solves the same triangle.
When every gap is a whole number and the sum under the root is below 1,000,000,000,000, the calculator also shows the exact answer in simplest radical form, such as 2√5 next to 4.4721, because homework usually asks for it.
Worked example with the default values
Point A = (1, 2) and Point B = (4, 6) in 2D:
- Δx = x₂ - x₁ = 4 - 1 = 3
- Δy = y₂ - y₁ = 6 - 2 = 4
- d² = Δx² + Δy² = 3² + 4² = 9 + 16 = 25
- d = √25 = 5
Switch to 3D with the default z values (z₁ = 3, z₂ = 15) and Δz = 12, so d = √(9 + 16 + 144) = √169 = 13. For a gap that is not a perfect square, try (1, 2) and (3, 5): d² = 13, so d = √13 ≈ 3.6056.
Limits and edge cases
- The formula treats the coordinates as flat. It is not right for latitude and longitude over long distances, because the Earth is curved. Use the haversine formula for that.
- Use the same unit for every coordinate. The answer is in that unit. Identical points give a distance of 0.
- Floating-point noise is removed, so 0.4 - 0.1 shows as 0.3. Very large answers appear in exponent form, for example 2e200.
- Decimal coordinates give a rounded decimal answer. The exact radical appears only when the gaps are whole numbers.
Need the point halfway between A and B? Use the midpoint calculator. For how steep the line between them is, use the slope calculator.
Frequently asked questions
Does the order of the points matter?
No. Swapping Point A and Point B flips the sign of Δx, Δy and Δz, but squaring removes the sign, so the distance is the same either way.
How do I leave the answer as a square root?
When the gaps between the coordinates are whole numbers, the calculator shows the exact answer beside the decimal, for example √13 or 2√5. If the gaps are decimals, only the rounded decimal is shown.
Can I use this for latitude and longitude?
Not for real-world distances. The formula assumes a flat plane, so it is only close for very short spans. For distances on Earth, use the haversine or great-circle formula, which accounts for the curve of the planet.
Is the distance formula the same as Manhattan distance?
No. The distance formula gives the straight-line (Euclidean) distance. Manhattan distance adds the absolute gaps, |Δx| + |Δy|, which is the length of a route along a street grid. The calculator shows both. For the default points the straight-line distance is 5 and the Manhattan distance is 7.
Sources: Wolfram MathWorld, Distance and Khan Academy, Distance formula.