Geometry & Trigonometry Coordinate Geometry, Lines & Coordinate Systems Euclidean metric in the Cartesian plane

Distance Formula Calculator (Two Points)

Enter the coordinates of two points and this calculator returns the straight-line distance between them, the exact answer in simplified radical form, the horizontal and vertical differences that produced it, the slope of the segment, and the taxicab distance for grid-constrained travel. The distance formula is nothing more than the Pythagorean theorem written in coordinates: the horizontal gap and the vertical gap are the legs of a right triangle, and the distance you want is its hypotenuse. Every step of the arithmetic is shown so you can reproduce it by hand.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
x₁The horizontal coordinate of the first point.-2
y₁The vertical coordinate of the first point.3
x₂The horizontal coordinate of the second point.4
y₂The vertical coordinate of the second point.-1
Coordinate unitUsed only as a label on the distance; the arithmetic is the same whatever the coordinates measure.generic units

It returns

  • Distance between the points — The length of the straight segment joining them.
  • Exact value in radical form — The simplified surd, when the sum of squares is a whole number.
  • Δx (horizontal difference)
  • Δy (vertical difference)
  • Slope of the segment — Δy divided by Δx; undefined for a vertical segment.
  • Taxicab distance — Distance if you can only travel along grid lines: |Δx| + |Δy|.

The formula

d=(x2x1)2+(y2y1)2
d1=|Δx|+|Δy|
d=a2+b2+c2

In plain text: d = √((x₂ − x₁)² + (y₂ − y₁)²)

  • dStraight-line distance between the two points (coordinate units)
  • x₁, y₁Coordinates of the first point (coordinate units)
  • x₂, y₂Coordinates of the second point (coordinate units)

The differences are squared, so the order of the two points makes no difference to the distance. Reversing them flips the sign of both differences and the squares erase it.

Updated Category Coordinate Geometry, Lines & Coordinate Systems Verified against published test cases Reading time 8 min

The distance formula is the Pythagorean theorem in disguise

Plot two points and drop a right angle between them: run horizontally from the first point until you are under the second, then climb vertically to reach it. Those two moves are the legs of a right triangle whose hypotenuse is the straight line you actually want. The horizontal leg has length |x₂ − x₁| and the vertical leg has length |y₂ − y₁|, so the Pythagorean theorem gives d² = Δx² + Δy².

There is no separate distance formula to memorise. Once you see the triangle, the formula writes itself, and that also explains why the absolute-value bars are unnecessary: squaring a negative difference gives the same result as squaring its positive twin. Subtracting the points in the other order flips the sign of both differences and changes nothing.

Because the formula only involves differences, it is invariant under translation: slide both points by the same amount in any direction and the distance is unchanged. It is also invariant under rotation about any centre, which is not obvious from the algebra but is the reason this particular expression, rather than any other combination of the coordinates, is the right notion of distance in the plane.

Reading the exact radical form

When both coordinates are whole numbers, the sum of squares is a whole number and the distance is the square root of an integer. Most of the time that root is irrational, and the honest answer is a surd rather than a decimal. The calculator simplifies it for you by pulling out the largest perfect square: √52 becomes 2√13, because 52 = 4 × 13.

Keeping the exact form matters when the distance feeds another calculation. Squaring 2√13 returns 52 exactly; squaring the rounded 7.211 returns 52.0 only to three figures. In a chain of steps that error compounds, which is why examination answers and geometric proofs stay in radical form until the very end.

Occasionally the root comes out whole. That happens exactly when Δx and Δy form a Pythagorean triple, and the small ones are worth recognising on sight: 3-4-5, 5-12-13, 8-15-17, 7-24-25 and 20-21-29, along with every multiple of each. Spotting 6 and 8 as a doubled 3-4-5 tells you the distance is 10 before you touch a calculator.

Worked example: the distance from (−2, 3) to (4, −1)

Take the two default points and work through them by hand.

  1. Find Δx. x₂ − x₁ = 4 − (−2) = 6. Subtracting a negative adds, which is the step most often fumbled.
  2. Find Δy. y₂ − y₁ = −1 − 3 = −4.
  3. Square both. 6² = 36 and (−4)² = 16. The sign vanishes here.
  4. Add. 36 + 16 = 52.
  5. Take the square root. d = √52 = 7.211102551.
  6. Simplify the surd. 52 = 4 × 13, and √4 = 2, so the exact distance is 2√13.

Two extras fall out of the same numbers. The slope of the segment is Δy ÷ Δx = −4 ÷ 6 = −2/3, so the line falls two units for every three you move right. The taxicab distance, if you could only travel along grid lines, is |6| + |−4| = 10 — about 39% further than the straight line, which is what a street grid costs you.

Check the answer for plausibility. The larger leg is 6, so the hypotenuse must exceed 6; the sum of the legs is 10, so it must be under 10. A result of 7.21 sits sensibly between them.

Euclidean distance versus taxicab distance

The straight-line figure is the right one whenever travel is unconstrained: a radio link, a rifle shot, a drone flight, the separation of two data points. The taxicab figure is the right one whenever movement is confined to axis-aligned paths: streets on a grid, warehouse aisles, the moves of a rook, or an integer lattice.

The two are equal only when the segment is exactly horizontal, exactly vertical, or of zero length, and the straight-line distance is never the larger of the two — that is the triangle inequality. The gap is widest along a 45-degree diagonal: for Δx = Δy = 1, the straight line is √2 = 1.414 while the taxicab route is 2, so the grid costs you 41.4%. For the example above, with Δx = 6 and Δy = −4, the straight line is 7.211 and the grid route is 10, a 38.7% penalty.

Neither figure is a travel distance on the Earth's surface. Latitude and longitude are angles on a sphere, not Cartesian coordinates, and a degree of longitude shrinks with the cosine of the latitude. Applying this formula to raw latitude and longitude will be wrong by a factor that grows as you move away from the equator; use a great-circle formula instead.

Common coordinate differences and their exact distances

Each distance is √(Δx² + Δy²) with the surd simplified. Rows where the distance is whole are Pythagorean triples.
ΔxΔyΔx² + Δy²Exact distanceDecimal
112√21.414214
125√52.236068
2282√22.828427
342555.000000
46522√137.211103
5121691313.000000
681001010.000000
7246252525.000000
8152891717.000000
991629√212.727922
20218412929.000000

Any multiple of a triple is another triple: 6-8-10 is the 3-4-5 doubled, and 9-12-15 is it tripled.

Mistakes that produce the wrong distance

  • Dropping a double negative. 4 − (−2) is 6, not 2. This single slip accounts for most wrong answers on negative coordinates.
  • Adding before squaring. (Δx + Δy)² is not Δx² + Δy². Square each difference first, then add.
  • Forgetting the square root. The formula returns d² until you take the root. Leaving it off gives 52 where the answer is 7.211.
  • Using latitude and longitude directly. Degrees on a sphere are not Cartesian coordinates; a degree of longitude is about 69 miles at the equator and zero at the pole.
  • Reporting a rounded decimal where an exact surd was asked for. 2√13 is exact; 7.21 is not, and squaring it will not return 52.

Key terms

Euclidean distance
The ordinary straight-line distance, √(Δx² + Δy²). It is the shortest possible path between two points in the plane.
Taxicab distance
Also called Manhattan or L1 distance: |Δx| + |Δy|. It is the shortest path when travel is restricted to axis-aligned moves.
Pythagorean triple
Three whole numbers a, b, c with a² + b² = c², such as 3-4-5 or 5-12-13. Coordinate differences forming a triple give a whole-number distance.

Where the distance formula leads next

Extending to three dimensions costs one extra term: d = √(Δx² + Δy² + Δz²), which the 3D distance calculator handles. The same pattern continues into any number of dimensions, and that generalisation is the basis of nearest-neighbour search and clustering in machine learning.

The formula is also the engine behind the equation of a circle. Saying that a point sits a fixed distance r from a centre (h, k) is exactly (x − h)² + (y − k)² = r², which is the distance formula with both sides squared. Every circle equation you meet is this one in disguise.

For the other properties of the same segment, the sibling tools do the work: the midpoint calculator finds its centre, the slope calculator gives its steepness and angle, and the line equation calculator turns the two points into y = mx + b. When you need the perpendicular gap from a point to a line rather than to another point, use the point-to-line distance calculator.

Frequently asked questions

What is the distance formula?

d = √((x₂ − x₁)² + (y₂ − y₁)²). Subtract the x-coordinates, subtract the y-coordinates, square both differences, add them, and take the square root. It is the Pythagorean theorem applied to the right triangle whose legs are the horizontal and vertical gaps between the points.

Does the order of the two points matter?

No. Swapping the points flips the sign of both differences, and squaring removes the sign, so the distance is identical. That is why the formula needs no absolute-value bars. The slope survives the swap too, for a different reason: it is Δy ÷ Δx, both signs flip together, and a negative divided by a negative is positive. What the order does change is the sign of Δx and Δy individually, so read those two outputs as directed from point 1 to point 2.

How do I leave the answer in exact radical form?

Simplify the square root by factoring out the largest perfect square. For √52, note that 52 = 4 × 13 and √4 = 2, so √52 = 2√13. If the number under the root has no square factor, such as 13 or 17, it is already fully simplified. The calculator shows this reduced form beside the decimal.

What is taxicab distance and when should I use it?

Taxicab distance is |Δx| + |Δy|, the length of the path when you may only travel along grid lines. Use it for street grids, warehouse aisles or lattice problems. It equals the straight-line distance only when the segment is horizontal or vertical, and the gap is largest along a 45-degree diagonal, where the grid route is √2 = 1.414 times the direct one.

Can I use this for latitude and longitude?

Not reliably. Latitude and longitude are angular coordinates on a sphere, and the ground distance covered by one degree of longitude shrinks as the cosine of the latitude — about 69 miles at the equator, and zero at the poles. Applying a flat-plane formula to them understates east-west distances everywhere except the equator. Use a great-circle calculation instead.

Why is the distance sometimes a whole number?

Because the coordinate differences happen to form a Pythagorean triple. If Δx = 3 and Δy = 4, the sum of squares is 25 and the root is exactly 5. The same happens for 5-12-13, 8-15-17, 7-24-25 and every multiple of each. Any other pair of whole-number differences gives an irrational distance.

How do I find the distance in three dimensions?

Add the third squared difference: d = √(Δx² + Δy² + Δz²). From (1,2,3) to (4,6,15), the differences are 3, 4 and 12, giving √(9 + 16 + 144) = √169 = 13. The pattern continues into any number of dimensions, which is how distance works in data analysis.

What is the distance from a point to the origin?

Set the second point to (0, 0) and the formula reduces to √(x² + y²), which is the magnitude of the position vector. For (−3, 4) that is √(9 + 16) = 5. This special case is also the modulus of the complex number x + iy, and the polar radius r in polar coordinates.

References

  • Euclid's Elements, Book I, Proposition 47 (the Pythagorean theorem) — Green Lion Press (Heath translation)
  • CRC Standard Mathematical Tables and Formulas, 33rd ed. — CRC Press
  • Precalculus: Mathematics for Calculus, 7th ed. — Cengage (Stewart, Redlin, Watson)