Distance Formula Calculator

Enter two points in 2D or 3D and get the distance between them, exact and as a decimal, with every step of the working, plus the midpoint, the slope and a scaled graph.

By the PythagoreanTheorem.net teamUpdated Free · no sign-up

Point A

Point B

d = 2√13 ≈ 7.2111

Exact value in simplest radical form, then the decimal rounded to 4 places.

  • Change in x6
  • Change in y4
  • Midpoint(1, 3)
  • Slope2/3 ≈ 0.6667
−4−202460246Δx = 6Δy = 4d ≈ 7.21A(−2, 1)B(4, 5)

Step-by-step solution

  1. Write the distance formula: d = √(x2 − x1)2 + (y2 − y1)2
  2. Substitute the coordinates: d = √(4 − (−2))2 + (5 − 1)2
  3. Subtract: d = √62 + 42
  4. Square: d = √36 + 16
  5. Add: d = √52
  6. Take the square root: d = 2√13 ≈ 7.2111
You can type negatives (−3), decimals (2.5), fractions (1/2) or roots (√2). The page address updates, so you can share the result.

The distance between two points (x1, y1) and (x2, y2) is d = √(x2 − x1)2 + (y2 − y1)2. Subtract the x-coordinates, subtract the y-coordinates, square both differences, add them and take the square root. This distance formula calculator does exactly that, shows each line of the working and plots both points on a coordinate grid.

How to use the distance calculator

  1. Choose 2D or 3D. Points on a flat graph have two coordinates, (x, y). Points in space, such as the corners of a box or positions in a video game, have three, (x, y, z).
  2. Type the coordinates of point A and point B. Negative numbers, decimals and fractions all work. It does not matter which point you call A.
  3. Read the distance. When the answer is a whole number you get it exactly. Otherwise you get the simplest radical form, such as 2√13, followed by the decimal.
  4. Check the extras. The tiles show the horizontal change Δx, the vertical change Δy, the midpoint of the segment and, in 2D, its slope. The graph rescales itself, so points far from the origin still fit.

The distance formula is the Pythagorean theorem

Draw a horizontal line from A and a vertical line from B. They meet at a right angle, so the segment AB is the hypotenuse of a right triangle. The horizontal leg has length |x2 − x1| and the vertical leg has length |y2 − y1|. The Pythagorean theorem, a2 + b2 = c2, then gives the distance directly.

2468 246810 6 8 d A(1, 2) B(7, 10) Δx = 7 − 1 = 6 Δy = 10 − 2 = 8 d² = 6² + 8² = 100 d = √100 = 10
The two differences in the coordinates are the legs of a right triangle. The distance between the points is its hypotenuse.

The squares are why the formula never needs absolute-value bars: (−6)2 and 62 are both 36, so it makes no difference if you subtract A from B or B from A. In three dimensions you add one more squared difference:

d = √(x2 − x1)2 + (y2 − y1)2 + (z2 − z1)2

That version comes from using the theorem twice, once across the floor of a box and once up to the opposite corner. The 3D Pythagorean theorem lesson draws it out, and the full derivation of the 2D formula is on the distance formula page.

Worked examples

Example 1: a whole-number answer

Find the distance between (1, 2) and (7, 10).

d= √(7 − 1)2 + (10 − 2)2= √62 + 82 = √36 + 64 = √100 = 10

The distance is 10. The legs 6 and 8 are the 3-4-5 triangle doubled.

Example 2: negative coordinates

Find the distance between (−3, 4) and (2, −8).

d= √(2 − (−3))2 + (−8 − 4)2= √52 + (−12)2 = √25 + 144 = √169 = 13

The distance is 13. Subtracting a negative means adding: 2 − (−3) = 5.

Example 3: a radical answer

Find the distance between (−2, 1) and (4, 5), the example loaded in the calculator.

d= √62 + 42 = √36 + 16 = √52= √4 · 13 = 2√13 ≈ 7.2111

The exact distance is 2√13, about 7.21. The square root simplifier shows how √52 becomes 2√13.

Example 4: two points in 3D

Find the distance between (1, 2, 3) and (4, 6, 15).

d= √32 + 42 + 122 = √9 + 16 + 144 = √169 = 13

The distance is 13. Switch the calculator to 3D to see this as the diagonal of a 3 × 4 × 12 box.

Example 5: decimals

Find the distance between (0.5, 1.5) and (2, 3.5).

d = √1.52 + 22 = √2.25 + 4 = √6.25 = 2.5

The distance is exactly 2.5.

More practice, with answers, is on the distance formula worksheet.

Midpoint and slope

Two more facts about a segment come from the same subtraction, so the calculator shows them as well.

  • Midpoint: average the coordinates, M = (x1 + x2 over 2, y1 + y2 over 2). For (1, 2) and (7, 10) the midpoint is (4, 6). It is marked with a small ring on the graph. In 3D you average the z-coordinates too.
  • Slope: rise over run, m = y2 − y1 over x2 − x1 = Δy over Δx. For the same points it is 8 over 6 = 4 over 3. A horizontal segment has slope 0. A vertical one has an undefined slope, because Δx = 0 and you cannot divide by zero.

TipThe distance and the slope use the same two differences. Distance squares and adds them; slope divides one by the other. If you have already worked out Δx and Δy for one, you are halfway to the other.

Common mistakes

  • Squaring a negative wrongly. (−12)2 = 144, not −144. A calculator typed as -12^2 gives −144, so use brackets.
  • Mixing coordinates. Subtract x from x and y from y. Writing x2 − y1 is the most common slip.
  • Taking the root too early. √36 + 16 is not 6 + 4. Add first, then take one square root. The common mistakes page explains why √a2 + b2 ≠ a + b.
  • Forgetting the root. d2 = 52 is not the distance. The distance is √52.

Straight-line distance versus walking distance

The distance formula measures the straight line between the points, often called the Euclidean distance or the distance "as the crow flies". On a street grid you usually cannot walk that line. You walk along the legs instead, which is always longer unless the points share a coordinate.

AB 4 blocks 3 blocks Along the streets 4 + 3 = 7 blocks Straight line √(4² + 3²) = 5 blocks
The straight-line distance is the hypotenuse; the walking route follows the two legs. The shortcut saves 2 blocks here.

The walking route, |Δx| + |Δy|, is sometimes called the taxicab or Manhattan distance. Both measures are used in practice. Delivery routing on a grid of streets cares about the walking distance; a drone, a radio signal or a ship crossing open water cares about the straight line.

Where the distance formula is used

  • Maps and navigation. On a local map with a square grid, the distance between two grid references is a direct application. Over long distances on the curved Earth, navigators use spherical formulas instead, as explained on the Pythagorean theorem on a sphere page.
  • Video games and graphics. Games check whether a character is within range of an object by computing the distance between their coordinates, often many times a second. See the Pythagorean theorem in computer science.
  • Physics. The size of a displacement or a velocity with components vx and vy is √vx2 + vy2, the same calculation. More on the physics page.
  • Circles. Every point at distance r from the center (h, k) satisfies (x − h)2 + (y − k)2 = r2, which is the distance formula squared. That is the equation of a circle.

Frequently asked questions

What is the distance formula?

For points (x1, y1) and (x2, y2), the distance is d = √(x2 − x1)2 + (y2 − y1)2. It is the Pythagorean theorem applied to the right triangle whose legs are the horizontal and vertical gaps between the points.

Does it matter which point is first?

No. Swapping the points changes the sign of each difference, but squaring removes the sign, so you get the same distance. The slope is also unchanged, because both the rise and the run change sign.

Can a distance be negative?

No. You add two squares, which are never negative, and take the positive square root. The smallest possible distance is 0, which happens only when the two points are the same.

How do you find the distance between two points in 3D?

Add a third squared difference for the z-coordinates: d = √(Δx)2 + (Δy)2 + (Δz)2. For (0, 0, 0) and (2, 3, 6) that is √4 + 9 + 36 = √49 = 7. Choose 3D in the calculator to work in space.

Why is my answer a square root instead of a decimal?

When Δx2 + Δy2 is not a perfect square, the exact distance is irrational, so any decimal is only an approximation. Teachers usually want the exact form, such as 3√5. The calculator gives both, and you can choose how many decimal places to round to.

Can I use this for latitude and longitude?

Only roughly, and only for short distances. Degrees of longitude get shorter as you move away from the equator, and the Earth is curved, so for real map coordinates you need a spherical distance formula. For points on a flat grid or a scale drawing, the distance formula is exact.

Keep exploring