Skip to content
Calculator.hair

What Is the Distance Formula?

By the Calculator.hair team · Updated · 6 min read

Short answer

The distance formula is d = √((x₂ − x₁)² + (y₂ − y₁)²). It gives the straight-line distance between two points on a coordinate plane. For (1, 2) and (7, 10), d = √(6² + 8²) = √(36 + 64) = √100 = 10. In three dimensions, add (z₂ − z₁)² under the square root.

Key takeaways

  • The distance formula is the Pythagorean theorem applied to the horizontal and vertical gaps between two points.
  • The order of the points does not matter, because squaring removes any minus sign.
  • For 3D points, add a third squared difference under the root.
  • The midpoint is the average of the coordinates: ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2).
  • Latitude and longitude need a different method because the Earth is curved and degrees are not a fixed length.

What is the distance formula?

The distance formula is d = √((x₂ − x₁)² + (y₂ − y₁)²), where (x₁, y₁) and (x₂, y₂) are two points and d is the straight-line distance between them. This straight-line length is also called the Euclidean distance. The result is always zero or positive, and it is in whatever units the coordinates use.

Our distance calculator solves it for any two points and shows the working, the midpoint and the slope of the line between them.

(x₁, y₁)(x₂, y₂)x₂ − x₁y₂ − y₁d
d = √(3² + 4²) = 5

How do you calculate the distance between two points?

Subtract the x-values, subtract the y-values, square both results, add them, and take the square root. Here are the steps for (1, 2) and (7, 10):

  • Find the horizontal difference: 7 − 1 = 6.
  • Find the vertical difference: 10 − 2 = 8.
  • Square both: 6² = 36 and 8² = 64.
  • Add them: 36 + 64 = 100.
  • Take the square root: √100 = 10.

How do you use the distance formula with negative coordinates?

Keep the signs through the subtraction, and remember that subtracting a negative number adds it. For (−2, 3) and (4, −5), the horizontal difference is 4 − (−2) = 6, and the vertical difference is −5 − 3 = −8. Squaring turns −8 into 64, so d = √(36 + 64) = 10.

Most answers are not whole numbers. For (2, 3) and (5, 9), d = √(9 + 36) = √45. You can leave that as an exact value, 3√5, or round it to 6.7082. The table shows these examples as our calculator reports them.

Point 1Point 2WorkingDistanceMidpoint
(1, 1)(4, 5)√(9 + 16)5(2.5, 3)
(0, 0)(3, 4)√(9 + 16)5(1.5, 2)
(1, 2)(7, 10)√(36 + 64)10(4, 6)
(−2, 3)(4, −5)√(36 + 64)10(1, −1)
(2, 3)(5, 9)√(9 + 36)6.7082039325(3.5, 6)

How does the distance formula relate to the Pythagorean theorem?

The distance formula is the Pythagorean theorem rewritten for coordinates. The theorem says that in a right triangle, a² + b² = c², where a and b are the two legs that meet at the right angle and c is the longest side, the hypotenuse.

Any two points that are not on the same horizontal or vertical line form the ends of a hypotenuse. Draw a horizontal line from one and a vertical line from the other, and they meet at a right angle. The legs have lengths |x₂ − x₁| and |y₂ − y₁|, and the straight line between the points is c. Solving for c gives the distance formula.

For (1, 2) and (7, 10), the legs are 6 and 8. Entering a = 6 and b = 8 in our Pythagorean theorem calculator returns c = 10, the same answer as the distance formula. Because the differences are squared, the absolute value bars are not needed in the formula. For more on right triangles, see triangle formulas.

abca²b²c²
a² + b² = c²: here 9 + 16 = 25.

What is the 3D distance formula?

The 3D distance formula is d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). It adds a third squared difference for the z-coordinate, which measures height or depth.

For (1, 2, 3) and (4, 6, 15), the differences are 3, 4 and 12. That gives d = √(9 + 16 + 144) = √169 = 13. The midpoint is (2.5, 4, 9). The 3D tool on our distance calculator returns the same values.

It is the Pythagorean theorem used twice. First find the flat distance across the x and y gaps: √(9 + 16) = 5. Then treat that 5 as one leg and the z gap of 12 as the other: √(25 + 144) = 13. This is also how you find the longest diagonal of a box. A 3 × 4 × 12 box has a corner-to-corner diagonal of 13.

What is the midpoint formula?

The midpoint formula is M = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2). It averages the x-values and the y-values to find the point exactly halfway between two points. For (1, 2) and (7, 10), M = (8 ÷ 2, 12 ÷ 2) = (4, 6).

You can check this using the distance formula. The distance from (1, 2) to (4, 6) is √(9 + 16) = 5, which is half of the full 10. To find a missing endpoint when you know one end and the midpoint, double the midpoint and subtract the known end. With the midpoint (4, 6) and the end (1, 2), the other end is (2 × 4 − 1, 2 × 6 − 2) = (7, 10).

The same pair of differences also gives the slope: 8 ÷ 6 ≈ 1.3333. See our slope formula guide or the slope calculator to go further with that line.

How do you calculate the distance between latitude and longitude points?

Use a method built for a curved Earth, not the flat distance formula. A degree of longitude gets shorter as you move toward the poles, so a difference in degrees does not convert to one fixed distance.

As an example, take 38.8976, −77.0366 in Washington, DC, and 39.9496, −75.1503 in Philadelphia. The table shows the results from our tool, which also reports 108.018 nautical miles. The two methods differ by about 0.22 km over this range. These are distances over the surface between the two coordinates. The tool does not account for roads or elevation, so driving distance will be longer. It also can't report an ellipsoid distance for points nearly opposite each other on the globe, and it shows a message when the calculation does not converge.

The latitude and longitude tool on our distance calculator takes decimal degrees or degrees, minutes and seconds, and it reports two surface distances:

  • An ellipsoid distance, using Vincenty's method on the WGS-84 model of the Earth, which treats the planet as slightly flattened at the poles.
  • A great-circle distance, using the haversine formula on a sphere with a mean radius of 6,371.0088 km. A great circle is the shortest path along the surface of a sphere.
MethodKilometersMiles
WGS-84 ellipsoid (Vincenty)200.05124.305
Great circle (haversine)199.831124.169
ABcR
The great-circle distance is the arc length R × c, where c is the central angle.

What mistakes should you avoid with the distance formula?

Most errors come from skipping the squares or mishandling a sign.

  • Adding the differences without squaring. For legs of 6 and 8, 6 + 8 = 14 is the path along the legs, not the straight-line distance of 10.
  • Distributing the square root. √(36 + 64) is √100 = 10, not √36 + √64 = 14.
  • Dropping a sign with negative coordinates. 4 − (−2) is 6, not 2.
  • Forgetting the final square root and reporting 100 as the distance.
  • Mixing units, such as x in feet and y in inches. Convert them first.
  • Confusing this with the travel formula. Distance = speed × time is a separate idea, covered in speed, distance and time.

Calculators in this guide

Frequently asked questions

What is the formula for the distance between two points?

d = √((x₂ − x₁)² + (y₂ − y₁)²). Square the horizontal and vertical differences, add them, and take the square root.

Does the order of the points matter?

No. Swapping the points changes the sign of each difference, but squaring removes it. Both orders of (1, 2) and (7, 10) give 10.

How do you find the distance from a point to the origin?

Use d = √(x² + y²), since the origin is (0, 0). The point (3, 4) is 5 units from the origin.

Can a distance be negative?

No. Squares can't be negative, and the square root returns a non-negative value. The distance is 0 only when the two points are the same.

What is a distance formula solver?

It is a tool that takes two points and returns the distance, usually with the working. Our distance calculator also gives the midpoint and slope for 2D points, and it has a separate 3D form.

Sources