Distance Formula Calculator

Compute the straight-line distance between two coordinate points using the Pythagorean theorem. Also returns slope, midpoint and line equation.

How this works

The distance formula gives the straight-line ("Euclidean") distance between two points in a 2D plane. It comes directly from the Pythagorean theorem applied to the right triangle whose legs are the horizontal change (x₂ − x₁) and the vertical change (y₂ − y₁): the diagonal hypotenuse is the distance you want. Squaring takes care of negative differences, and the square root brings the answer back into the same units as the original coordinates.

It generalises to higher dimensions trivially. In 3D, distance = √(dx² + dy² + dz²); in n dimensions, sum the squared differences across all coordinates and take the root. This is why "Euclidean distance" is the default similarity measure in machine learning and statistics whenever you have feature vectors — it's just the multi-dimensional version of the same formula. Other distance metrics (Manhattan, Chebyshev, cosine) exist for specific use cases, but Euclidean is what people mean when they say "distance" without qualifying it.

Real-world catches: if your coordinates are latitude/longitude, plain Euclidean distance is wrong because the Earth is curved — use the haversine formula instead, which accounts for great-circle arc length on a sphere. For city-scale distances within a few kilometres the error is small, but at hundreds of kilometres Euclidean undershoots the true geodesic distance noticeably. The same applies to any curved surface (a globe, a contour map, a video-game world with terrain).

The formula

distance d = √((x₂ − x₁)² + (y₂ − y₁)²) 3D: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²) n-D: d = √(Σ (cᵢ₂ − cᵢ₁)²) for each coordinate i

(x₁, y₁) and (x₂, y₂) are the two points. Squaring eliminates sign so the formula works regardless of which point you treat as "first". Distance is always non-negative; it equals zero only when the two points are identical.

Example calculation

  • Distance between (1, 2) and (4, 8).
  • dx = 4 − 1 = 3, dy = 8 − 2 = 6. d = √(9 + 36) = √45 ≈ 6.708.
  • For (2, 3, 5) and (5, 7, 9) in 3D: d = √(3² + 4² + 4²) = √41 ≈ 6.403.

Frequently asked questions

Does the order of the points matter?

No. Because the differences are squared, (x₂ − x₁)² and (x₁ − x₂)² are equal. Distance from A to B always equals distance from B to A — that's the symmetry property of any valid distance metric.

How is this different from displacement or arc length?

Distance (this formula) is a straight line — the shortest possible path. Displacement is a vector with both magnitude (the distance) and direction. Arc length is the distance along a curved path; it's always ≥ the straight-line distance, equal only when the curve happens to be a straight line. Real-world travel distance ("how far did I drive?") is arc length following the road network, not straight-line distance.

Can this work for latitude/longitude on Earth?

Not really. Lat/lon coordinates live on a curved sphere, so plain Euclidean distance is wrong, especially over long distances. Use the haversine formula, which computes the great-circle arc length on a sphere. For short distances (under a few km within one city), the error is small enough to not matter; over hundreds of km, Euclidean undershoots noticeably.

Related calculators