acalculator

How do I use the distance formula?

Type the coordinates of two points. The distance formula calculator shows the distance as an exact square root and a decimal, with every step.

Your numbers

Points in
Distance d
5

The distance between the two points is 5.

Exact distance
5
Distance squared d²
25
Δx = x₂ − x₁
3
Δy = y₂ − y₁
4
Working
d = √((4 − 1)² + (6 − 2)²); d = √(3² + 4²) = √(9 + 16) = √25; d = 5

Distance d: 5. The distance between the two points is 5.

Where are the points?

How is the distance found?

How to calculate

Finds the distance between two points in 2D or 3D with the distance formula, as an exact square root and a decimal, with each step of the working.

Example with the default inputs (Points in 2D (x, y), x₁ 1, y₁ 2, x₂ 4, y₂ 6): The distance between the two points is 5.

Method: d = √((x₂ − x₁)² + (y₂ − y₁)²), with + (z₂ − z₁)² inside the root for points in 3D.

  • Coordinates are read exactly as typed (0.1 is 1/10), so d² is exact; the decimal distance is its square root rounded for display.
  • The distance is in the same unit as the coordinates.
  • The drawing shows the x and y coordinates only, also for points in 3D.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Points in 2D (x, y), x₁ 1, y₁ 2, x₂ 4, y₂ 6 gives Distance d 5, Exact distance 5, Distance squared d² 25, Δx = x₂ − x₁ 3, Δy = y₂ − y₁ 4, Working d = √((4 − 1)² + (6 − 2)²); d = √(3² + 4²) = √(9 + 16) = √25; d = 5.Source: OpenStax, College Algebra 2e, §2.1, the distance formula (https://openstax.org/books/college-algebra-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs)
  2. Points in 2D (x, y), x₁ -3, y₁ 5, x₂ 3, y₂ 2 gives Distance d 6.708204, Exact distance 3√5, Distance squared d² 45, Δx = x₂ − x₁ 6, Δy = y₂ − y₁ -3.
  3. Points in 3D (x, y, z), x₁ 1, y₁ 2, z₁ 3, x₂ 4, y₂ 6, z₂ 15 gives Distance d 13, Exact distance 13, Distance squared d² 169, Δz = z₂ − z₁ 12.
  4. Points in 2D (x, y), x₁ 0, y₁ 0, x₂ 0.5, y₂ 0.5 gives Distance d 0.707107, Exact distance √2/2, Distance squared d² 0.5.
  5. Points in 2D (x, y), x₁ 0.1, y₁ 0, x₂ 0.4, y₂ 0.4 gives Distance d 0.5, Exact distance 1/2, Distance squared d² 0.25.

How it works

For two points on a plane, (x₁, y₁) and (x₂, y₂):

d = √((x₂ − x₁)² + (y₂ − y₁)²)

For two points in space, (x₁, y₁, z₁) and (x₂, y₂, z₂):

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

The calculator also shows the differences Δx = x₂ − x₁, Δy = y₂ − y₁ (and Δz = z₂ − z₁ in 3D) and the distance squared, d² = Δx² + Δy² (+ Δz²).

Exact answer

Each coordinate is read exactly as its decimal (0.1 is 1/10), so the differences and d² are exact fractions. Write d² as p/q in lowest terms. When p × q is at most 10¹², the calculator writes d = √(p/q) = √(pq) ÷ q in simplest form: it takes the largest square factor out of pq, so √(pq) = k√m with m having no square factor, then cancels the common factor of k and q. The exact answer is written:

  • k/n or k when m = 1 (for example 5 or 1/2),
  • k√m/n, leaving out k when it is 1 and "/n" when n is 1 (for example 3√5, √2/2, 3√2/4),
  • 0 when the points are the same.

When p × q is more than 10¹², only the decimal shows.

Decimal answer and the working

The decimal distance is the square root of d² (d² rounded to the nearest 64-bit float first); if d² is outside the range of a normal 64-bit float, it is computed from the differences without overflow. d² itself shows only when it fits a 64-bit float (up to about 1.8 × 10³⁰⁸); for points farther apart it is left out, and the distance still shows. It shows with at most 6 decimals (6 significant figures below 0.0001), rounded half up on the decimal value.

The working has three steps, written like this for 2D (3D adds the z terms):

  1. d = √((x₂ − x₁)² + (y₂ − y₁)²) with the coordinates put in
  2. d = √(<Δx>² + <Δy>²) = √(<Δx²> + <Δy²>) = √<d²>, with each difference, each square, and d² as numbers
  3. d = <exact> when the exact answer has no square root; d = <exact> ≈ <decimal> when it has one; d ≈ <decimal> when there is no exact answer

Numbers in the working are decimals rounded half up to 10 significant figures, written like a JavaScript number (plain from 0.000001 up to below 10²¹, else e notation). Negative numbers are in brackets, for example (-3)². The subtraction sign is −, the minus of a negative number is -.

Assumptions

  • The distance is in the same unit as the coordinates.
  • Points so far apart that a difference is beyond what a 64-bit float can hold give no answer ("The points are too far apart to show the distance.").
  • The drawing shows the x and y coordinates only, also in 3D.

Worked examples by hand

From (1, 2) to (4, 6). Δx = 4 − 1 = 3, Δy = 6 − 2 = 4. d = √(3² + 4²) = √(9 + 16) = √25 = 5.

From (−3, 5) to (3, 2). Δx = 3 − (−3) = 6, Δy = 2 − 5 = −3. d = √(36 + 9) = √45 = √(9 × 5) = 3√5 = 6.708204.

From (1, 2, 3) to (4, 6, 15) in 3D. Δx = 3, Δy = 4, Δz = 12. d = √(9 + 16 + 144) = √169 = 13.

From (0, 0) to (0.5, 0.5). d² = 0.25 + 0.25 = 1/2, so d = √(1/2) = √2 ÷ 2 = √2/2 = 0.707107.

From (0.1, 0) to (0.4, 0.4). Read exactly, Δx = 0.3 and Δy = 0.4, so d² = 0.09 + 0.16 = 0.25 and d = 1/2 = 0.5.

Other questions people ask

What is the distance formula?

For points (x₁, y₁) and (x₂, y₂), d = √((x₂ − x₁)² + (y₂ − y₁)²). It is the Pythagorean theorem: the horizontal and vertical gaps are the legs of a right triangle, and the distance is its hypotenuse.

How do I find the distance between two points step by step?

Subtract the x values and the y values, square both differences, add them, and take the square root. From (1, 2) to (4, 6): the differences are 3 and 4, the squares 9 and 16, the sum 25, and the distance √25 = 5.

How do I simplify the square root in the answer?

Take out the largest square factor. √45 = √(9 × 5) = 3√5, and √(1/2) = √2/2. The calculator does this for you whenever the sum of squares is a fraction with a small enough top and bottom.

Does the order of the points matter?

No. Swapping the points changes the sign of each difference, but squaring removes the sign, so the distance is the same. Δx and Δy do change sign.

How do I find the distance between points in 3D?

Add the third difference inside the root: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). From (1, 2, 3) to (4, 6, 15) the differences are 3, 4, and 12, so d = √(9 + 16 + 144) = √169 = 13.

Can the distance be negative?

No. It is a square root of a sum of squares, so it is 0 when the points are the same and positive otherwise.

Can I use this for distances on a map?

Only on a flat grid, such as a floor plan or a map zoomed in on a small area. For places far apart on the Earth, use a great-circle distance, because the surface is curved.