Lines & Graphs

Distance Formula: How to Find the Distance Between Two Points

The distance formula says the straight-line distance between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is

d=(x2−x1)2+(y2−y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

Try it with your numbers

Show every step

Subtract the x-values, subtract the y-values, square both results, add them, and take the square root.

This is the Pythagorean theorem in coordinate form, so there is almost nothing to memorize. Once you see the triangle hiding inside it, sign slips and misplaced square roots become easy to catch. The sections below cover the proof, negatives and fractions, radical answers, related formulas, a fast way to check your work, and real uses.

Where the distance formula comes from

Take any two points that do not share a row or column. From the first point, draw a horizontal line. From the second, draw a vertical line. They meet at a corner, and the three points form a right triangle with the segment you want as the hypotenuse.

The horizontal leg has length ∣x2−x1∣|x_2 - x_1| and the vertical leg has length ∣y2−y1∣|y_2 - y_1|. The Pythagorean theorem gives d2=∣x2−x1∣2+∣y2−y1∣2d^2 = |x_2 - x_1|^2 + |y_2 - y_1|^2. Squaring wipes out the absolute value bars, because ∣a∣2=a2|a|^2 = a^2 for every real number, so the bars disappear:

d2=(x2−x1)2+(y2−y1)2d^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2

That one fact explains two things students often ask about. The formula never needs absolute values, and it does not matter which point you call first, since (a−b)2=(b−a)2(a-b)^2 = (b-a)^2. If plotting points on the coordinate plane still feels shaky, practice plotting points first, because the formula is a description of the picture you would draw.

Quick check

Find the distance between (0,0)(0, 0) and (9,12)(9, 12).

How do you use the distance formula step by step?

The process is the same every time, and it is worth doing in this order so errors have nowhere to hide.

  1. Label the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).
  2. Subtract in the same order for both coordinates.
  3. Square each difference and add the two squares.
  4. Take the square root of the sum.

Example 1. Find the distance between (2,−1)(2, -1) and (6,4)(6, 4).

The differences are x2−x1=6−2=4x_2 - x_1 = 6 - 2 = 4 and y2−y1=4−(−1)=5y_2 - y_1 = 4 - (-1) = 5. Then:

d=42+52=16+25=41≈6.40d = \sqrt{4^2 + 5^2} = \sqrt{16 + 25} = \sqrt{41} \approx 6.40

The exact answer is 41\sqrt{41}. The decimal is only an approximation, so keep the radical until the last line and round once at the end.

The square root acts like a grouping symbol over everything beneath it, so the addition must finish before the root is taken. If that rule ever wobbles, a few order of operations practice problems will fix it. For more repetitions on this exact skill, use the distance formula practice problems.

Distance formula with negative coordinates and fractions

Negatives cause most of the lost points. When y1y_1 is negative, the subtraction y2−y1y_2 - y_1 turns into an addition, as in 4−(−1)=54 - (-1) = 5. A reliable way to think about it: the difference is how many steps lie between two numbers on a number line. From −1-1 up to 44 is five steps, because the path crosses zero. When two points sit in different quadrants of the graph, the gap crosses an axis and the two sizes add instead of subtract.

The squaring trap

(−3)2=9(-3)^2 = 9, but −32=−9-3^2 = -9. When a difference is negative, keep it in parentheses before squaring.

Example 2. Find the distance between (12,3)\left(\tfrac{1}{2}, 3\right) and (52,12)\left(\tfrac{5}{2}, \tfrac{1}{2}\right).

The differences are 52−12=2\tfrac{5}{2} - \tfrac{1}{2} = 2 and 12−3=−52\tfrac{1}{2} - 3 = -\tfrac{5}{2}. Squaring gives 44 and 254\tfrac{25}{4}, and 4=1644 = \tfrac{16}{4}, so:

d=164+254=414=412≈3.20d = \sqrt{\tfrac{16}{4} + \tfrac{25}{4}} = \sqrt{\tfrac{41}{4}} = \frac{\sqrt{41}}{2} \approx 3.20

There is a shortcut for fractions. Multiply every coordinate by the common denominator, find the distance, then divide by that same number. Here, doubling gives (1,6)(1, 6) and (5,1)(5, 1), whose distance is 42+52=41\sqrt{4^2 + 5^2} = \sqrt{41}. Halving gives the same 412\tfrac{\sqrt{41}}{2}. Scaling every coordinate by kk scales every distance by kk, which is why this works.

How do you simplify a distance formula answer with a radical?

Most distances are not whole numbers, and many teachers want the exact simplified radical. Look for the largest perfect square that divides the number under the root, then pull its square root out front.

Example 3. Find the distance between (−2,1)(-2, 1) and (4,7)(4, 7).

The differences are 4−(−2)=64 - (-2) = 6 and 7−1=67 - 1 = 6. So:

d=36+36=72=36⋅2=62≈8.49d = \sqrt{36 + 36} = \sqrt{72} = \sqrt{36 \cdot 2} = 6\sqrt{2} \approx 8.49

When both differences are equal in size, the segment is the diagonal of a square, and the distance is the leg times 2\sqrt{2}. Spotting that gives 626\sqrt{2} with no arithmetic at all.

Under the root Simplified
8\sqrt{8} 222\sqrt{2}
12\sqrt{12} 232\sqrt{3}
20\sqrt{20} 252\sqrt{5}
50\sqrt{50} 525\sqrt{2}
72\sqrt{72} 626\sqrt{2}

Never split the root across the sum. 9+16=5\sqrt{9 + 16} = 5, not 3+4=73 + 4 = 7. The root covers the whole sum, and roots do not distribute over addition.

Distance formula vs slope formula and midpoint formula

Three formulas use the same two subtractions and answer three different questions. Mixing them up is common because the setups look alike.

  • The slope formula divides: y2−y1x2−x1\frac{y_2 - y_1}{x_2 - x_1} tells you steepness.
  • The midpoint formula averages: (x1+x22,y1+y22)\left(\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2}\right) tells you the center.
  • The distance formula squares, adds and roots: it tells you length.

One difference matters in practice. Slope and distance both need the subtractions in a consistent order, but slope can flip sign if you are sloppy, while distance cannot, because every term is squared. A negative distance is therefore always a sign that something went wrong.

Try this: Take (1,1)(1, 1) and (4,5)(4, 5). Find the distance, the slope and the midpoint, using the same two subtractions for each. You should get 55, 43\tfrac{4}{3} and (52,3)\left(\tfrac{5}{2}, 3\right).

Distance formula for horizontal and vertical segments

If two points share a y-value, the vertical difference is zero and the formula collapses to d=∣x2−x1∣d = |x_2 - x_1|. For (−3,2)(-3, 2) and (5,2)(5, 2) the distance is ∣5−(−3)∣=8|5 - (-3)| = 8. The same happens with a shared x-value. You can read these off the graph without any root, and they are exactly the cases covered in horizontal and vertical lines.

This gives a neat use with intercepts. The line 3x+4y=123x + 4y = 12 crosses the axes at (4,0)(4, 0) and (0,3)(0, 3), so the segment between its intercepts has length 42+32=5\sqrt{4^2 + 3^2} = 5. If you need to find those crossing points first, see finding x and y intercepts. The distance from the origin to any point is the shortened form x2+y2\sqrt{x^2 + y^2}.

Know where the formula stops working. It measures a straight line only. It says nothing about a route along streets or a curved path, and it assumes a flat plane.

How can you check a distance answer in ten seconds?

Number line from 0 to 10 showing distance must lie between 5 and 9 for legs 4 and 5
For legs 4 and 5, only answers between 5 and 9 can be right, so 3 and 9.5 fail while √41 passes.

Before you trust a result, test it against three quick facts. First, the distance can never be shorter than the longer leg, and never longer than the two legs added together. In Example 1 the legs are 44 and 55, so dd must land between 55 and 99. The answer 41≈6.4\sqrt{41} \approx 6.4 passes. An answer of 33 or 9.59.5 would flag an error immediately.

Second, estimate the root using neighboring perfect squares. Because 36<41<4936 < 41 < 49, the root sits between 66 and 77, and since 4141 is nearer to 3636, a little above 66 is right.

Triple spotting

Legs of 55 and 1212 give 1313, and legs of 88 and 1515 give 1717. Multiples such as 6,8,106, 8, 10 keep the pattern, so some answers come out whole at a glance.

Third, swap the order of the points and recompute. If the squared differences come out the same, the setup was sound. This also catches the most common slip, a dropped negative sign, because only one version of the subtraction will tend to be wrong.

Quick check

Without a calculator, between which two whole numbers is the distance from (0,0)(0, 0) to (4,6)(4, 6)?

How is the distance formula used for triangles and circles?

Triangle A(0,0), B(3,1), C(1,-3) on a grid with squared sides 10, 10, 20 showing a right angle
Comparing squared side lengths skips the roots and shows the right angle at A.

Geometry problems often hand you three points and ask what kind of triangle they make. Compute the squared side lengths, which skips the roots entirely, and test the Pythagorean relationship.

Take A(0,0)A(0, 0), B(3,1)B(3, 1) and C(1,−3)C(1, -3). Then AB2=9+1=10AB^2 = 9 + 1 = 10, AC2=1+9=10AC^2 = 1 + 9 = 10 and BC2=4+16=20BC^2 = 4 + 16 = 20. Since 10+10=2010 + 10 = 20, the triangle has a right angle at AA, and the equal sides make it isosceles. A second method confirms it: the slopes of ABAB and ACAC are 13\tfrac{1}{3} and −3-3, and their product is −1-1, the signature of perpendicular lines. This also gives a clean way to classify a right angle without a protractor.

A circle is simply the distance formula held fixed. Every point (x,y)(x, y) at distance rr from the center (h,k)(h, k) satisfies (x−h)2+(y−k)2=r2(x - h)^2 + (y - k)^2 = r^2. A circle centered at (2,−1)(2, -1) passing through (5,3)(5, 3) has radius 32+42=5\sqrt{3^2 + 4^2} = 5, so its equation is (x−2)2+(y+1)2=25(x - 2)^2 + (y + 1)^2 = 25. Three points are collinear when the two shorter distances add up exactly to the longest one.

Quick check

Is the triangle with vertices A(0,0)A(0, 0), B(4,2)B(4, 2) and C(−1,2)C(-1, 2) a right triangle?

Where is the distance formula used in real life?

Any time positions are stored as coordinates, this formula measures the gap. Video games use it to decide whether a character is within reach of an object, and apps use it to find the nearest store on a flat map. Scale is a related idea: on a map, real distance is proportional to measured distance, which is a case of direct variation.

Add a third coordinate and the idea carries into space: d=(x2−x1)2+(y2−y1)2+(z2−z1)2d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2}. The points (1,2,3)(1, 2, 3) and (4,6,15)(4, 6, 15) have differences 33, 44 and 1212, so d=9+16+144=169=13d = \sqrt{9 + 16 + 144} = \sqrt{169} = 13. Data science uses the same idea in many dimensions as Euclidean distance.

Two limits are worth knowing. On Earth, long distances follow a curved surface, so navigation uses the great-circle (haversine) formula rather than a flat plane. For a city grid where you can only travel along blocks, the relevant measure is the taxicab distance ∣x2−x1∣+∣y2−y1∣|x_2 - x_1| + |y_2 - y_1|, which is 77 blocks from (0,0)(0, 0) to (3,4)(3, 4) even though the straight-line distance is 55. When you want to pair distance with its partner, the midpoint formula practice problems are a good next step.

Practice problems

0 of 5 solved

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

  2. Find the distance between (−3,−1)(-3, -1) and (2,11)(2, 11).

  3. Find the exact distance between (0,5)(0, 5) and (−4,−3)(-4, -3), then round to two decimal places.

  4. Find the distance between (−12,2)\left(-\tfrac{1}{2}, 2\right) and (32,−1)\left(\tfrac{3}{2}, -1\right).

  5. The distance between (1,2)(1, 2) and (k,6)(k, 6) is 55. Find every possible value of kk.

Common questions

What is the distance formula?

The distance formula is d=(x2−x1)2+(y2−y1)2d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}. It gives the straight-line length of the segment joining (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). It comes straight from the Pythagorean theorem.

Does it matter which point is (x1, y1) and which is (x2, y2)?

No. Swapping the points flips the sign of each difference, and squaring removes the sign. You only need to keep the same order within the x subtraction and within the y subtraction.

Can a distance be negative?

No. The square root symbol returns the non-negative root, and the squared terms are never negative. If you get a negative answer, a sign error happened outside the formula.

How do you find the distance between two points with a negative coordinate?

Put the negative coordinate in parentheses before subtracting, so 4−(−1)4-(-1) becomes 4+1=54+1=5. Then square each difference as usual. The squares are always positive.

What is the distance formula in 3D?

Add a third squared difference: d=(x2−x1)2+(y2−y1)2+(z2−z1)2d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}. For example, the points (1,2,3)(1, 2, 3) and (4,6,15)(4, 6, 15) are 1313 units apart.

Is the distance formula the same as the slope formula?

No. Both use the differences x2−x1x_2-x_1 and y2−y1y_2-y_1, but the slope divides them and the distance squares them, adds, and takes a root. Slope measures steepness, distance measures length.

Up next