Math calculator

Distance Formula Calculator

Straight-line distance, with the exact part kept exact.

Between two points

Two coordinates, or three.

√((3)² + (4)²) = √25

5

The root comes out whole, so these points are a Pythagorean-triple distance apart.

Straight-line distance

5

exact — a whole number

Squared distance

25

exact, before the root

Manhattan distance

7

along the grid, not across it

Largest single gap

4

the Chebyshev distance

The gap in each direction

The change in each coordinate between the two points, and its square
AxisFromToChangeSquared
x0339
y04416
  • The squared distance is exact: (3)² + (4)² = 25. Only the square root at the end is decimal.
  • The root comes out whole, so these points are a Pythagorean-triple distance apart — 5 exactly.
  • The distance formula is Pythagoras: the gaps in each coordinate are the legs of a right triangle and the distance is the hypotenuse. In three dimensions the same argument runs twice, which is why a third squared term simply joins the sum.
  • Manhattan distance — 7 — is the route along the grid rather than across it. It is never shorter than the straight line, and it is what a taxi, a chess rook or an L1 norm measures.
  • The order of the two points does not matter. Swapping them negates every difference, and squaring removes the sign.

The squared distance is computed on exact fractions, so a coordinate of 1/3 contributes exactly a ninth.

What this tool shows

The distance from (0,0) to (3,4) is 5 exactly. From (0,0) to (1,1) it is √2, which no decimal captures. The squared distance is always exact — it is a sum of squares — and only the final root is not, which is worth seeing separately.

  • Distance between two points in the plane
  • The same in three dimensions
  • The gap along each axis
  • The exact squared distance
  • Manhattan distance, along the grid
  • When the answer comes out whole
2D and 3D Squared distance exact Manhattan too Per-axis breakdown

Exact squared distance; decimal root.

Updated 7 September 2026 · Works in any browser, no installation

Square the gap on each axis, add them, take the root. From (0,0) to (3,4): 3² + 4² = 25, and √25 = 5. The order of the two points does not matter, because squaring removes the sign — which is exactly why the formula has no direction in it.

At a glance

Formula shown
In the plane, d = \u221a((x\u2082 \u2212 x\u2081)\u00b2 + (y\u2082 \u2212 y\u2081)\u00b2). In space a third squared term joins the sum. The squared distance is exact for rational coordinates; the root generally is not.
Scenario support
The straight-line gap between two points on a plan or a map; the length of a segment given its endpoints; checking whether three points form a right triangle.
Educational estimate
Planning support from the values you enter — not professional advice.

It is just Pythagoras

The distance formula is not a separate thing to learn. Draw the horizontal and vertical gaps between two points and they are the two legs of a right triangle; the distance is the hypotenuse.

So √((x₂−x₁)² + (y₂−y₁)²) is √(a² + b²) with a and b named after where they came from.

Seeing it that way makes two things obvious. The order of the points is irrelevant, because swapping them negates both legs and squaring undoes that. And the answer is never negative, because a hypotenuse is a length.

Three dimensions

A third squared term simply joins the sum: d = √((Δx)² + (Δy)² + (Δz)²).

The reason is Pythagoras applied twice. The horizontal gap across the floor is √(Δx² + Δy²), and that horizontal distance and the vertical rise form a second right triangle whose hypotenuse is the answer. Squaring the first root cancels it, and the three terms end up in one sum.

It keeps extending. In any number of dimensions the distance is the root of the sum of the squared differences — which is why the same formula turns up as the magnitude of a vector and the Euclidean norm in data work, with no visible triangle anywhere.

Manhattan and the other distances

Straight-line distance is one answer to “how far apart”. It is not always the useful one.

Manhattan distance adds the gaps instead of squaring them: |Δx| + |Δy|. It is the route along a grid rather than across it — what a taxi drives in a city laid out in blocks, and what an L1 norm measures. It is never shorter than the straight line, and often considerably longer.

Chebyshev distance takes the largest single gap. It is how far a chess king walks, since a diagonal step covers both axes at once.

The page reports all three, because which one is right depends on what can actually move and how.

Why the squared value is worth having

The squared distance is exact and the distance usually is not, and there are times when that matters.

Comparing. To find which of several points is nearest, comparing squared distances gives the same ordering and skips every square root. Nearest-neighbour code does this routinely.

Exactness. Two points at √2 apart have a squared distance of exactly 2. The decimal 1.4142135624 is not the distance, and a chain of calculations built on it accumulates error that the exact form does not.

Checking for a right angle. Three points form a right triangle exactly when one squared distance equals the sum of the other two — a test in whole numbers, with no roots involved.

Where it gets used

Plans and maps. The straight-line gap between two surveyed points, or between two pixels on a scaled drawing.

Graphics and games. Collision checks, view distances, nearest-object lookups. Almost always done on the SQUARED distance, for the reason above.

Data work. Euclidean distance between two rows of numbers is the same formula in as many dimensions as there are columns, and it is the default measure behind k-means and nearest-neighbour methods.

Geometry problems. Proving a shape is a rhombus, an isosceles triangle or a square usually reduces to computing a few distances and comparing them.

Where it does not apply

On a sphere. The Earth is not flat, and the straight-line distance between two cities passes through the ground. Great-circle distance uses spherical trigonometry instead, and over long distances the two answers differ substantially.

When movement is constrained. A straight line is only the distance if you can travel it. In a building, a city grid or a maze, the route matters more than the gap.

When the axes are not comparable. Distance between (age, salary) points treats a year and a pound as the same size, which they are not. Data has to be scaled before Euclidean distance means anything.

Sources and methodology

The formula is Pythagoras in coordinates; these are the references.

Method. The coordinate gaps and the sum of their squares are carried as exact rationals, so a coordinate of 1/3 contributes exactly a ninth and the squared distance is reported without rounding. Only the final square root is taken in double precision, and the page says which of the two numbers is which. Whether the root is a whole number is tested against the exact squared value rather than by looking at the decimal. That engine is verified on every change against 67 hand-written assertions, including agreement with a direct hypotenuse computation across four thousand generated pairs, and that the reported distance squared always reproduces the exact squared value. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

MidpointThe midpoint of a segment, plus the reverse problem nobody else solves: given one endpoint and the midpoint, where is the other endpoint?
SlopeSlope as an exact fraction, with the vertical case reported as undefined rather than as a division by zero — and the angle, gradient percentage and both related slopes alongside it.
Pythagorean Theorema² + b² = c² solved for whichever side you leave blank, with the triangle drawn to scale and integer triples reduced to their primitive.
VectorMagnitude, unit vector, sum, both products and the projection — with parallelism decided on the cross product, so exactly parallel vectors return exactly 0° and not a millionth of a degree.
Line EquationThe equation of a line in all three standard forms from two points or from a point and a slope, with the intercepts and the vertical case that has no y = mx + c form at all.
TriangleSolve any triangle from three measurements — and when two sides and a non-included angle describe TWO triangles, this one shows both instead of picking one.

More in Math, or browse all calculators.

Read the guide

The midpoint of the same two points needs no square root at all — the Midpoint Calculator gives it exactly — and the Slope Calculator turns the same two gaps into a gradient.

Educational use disclaimer

This is an educational tool. The squared distance is exact for the coordinates entered; the distance itself involves a square root and is decimal unless it happens to come out whole.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the distance page keeping the answer exact where the square root does not come out, since √50 simplified to 5√2 is what an exam wants and 7.0710678 is what hides the structure.
  2. The formula is Pythagoras on the coordinate differences, and the page says so — the horizontal and vertical gaps are the two legs, and the distance is the hypotenuse.
  3. Squaring removes the sign, so the order of the two points never matters; that is stated rather than left for the reader to discover.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.