The distance formula in coordinate geometry is d = √[(x2 − x1)2 + (y2 − y1)2]. It gives the straight-line distance between points (x1, y1) and (x2, y2) on a flat Cartesian plane. Subtract matching coordinates, square the differences, add them, then take the square root.

Distance is a length, so it uses ordinary units such as cm, metres or coordinate units. It cannot be negative. The formula works with positive, negative, fractional and decimal coordinates, provided the measurements use a consistent scale.

Distance formulas at a glance

SituationFormulaCondition
Two points in a planed = √[(x2 − x1)2 + (y2 − y1)2]Any two Cartesian points
Horizontal segmentd = |x2 − x1|The y-coordinates are equal
Vertical segmentd = |y2 − y1|The x-coordinates are equal
Distance from the origind = √(x2 + y2)One endpoint is (0,0)
Squared distanced2 = (Δx)2 + (Δy)2Useful for comparing lengths
Three-dimensional distanced = √[(Δx)2 + (Δy)2 + (Δz)2]Points have x, y and z coordinates

Symbols: d is distance; Δx = x2 − x1 and Δy = y2 − y1. In three dimensions, Δz = z2 − z1. Vertical bars mean absolute value, which makes a difference non-negative.

Read the coordinate diagram

Distance between A at one, one and B at five, four On a coordinate grid with equal unit steps, A is at (1,1) and B is at (5,4). A dashed horizontal leg goes four units right to (5,1), then a dashed vertical leg goes three units up to B. A right-angle marker joins these legs. The blue straight segment from A to B is the hypotenuse and has length five units. 1234567123450 xy A (1, 1)B (5, 4)d = 5 Δx = 4Δy = 3 Each grid step is one unit on both axes.
The horizontal change is 4 units and the vertical change is 3 units. Pythagoras gives d = √(4² + 3²) = 5 units for the straight segment.

The blue line is the direct distance. The dashed legs show the horizontal and vertical changes. Travelling along both legs would cover 4 + 3 = 7 units. The straight segment is shorter: 5 units.

Why the formula works

Draw a horizontal line from one endpoint and a vertical line from the other. Together with the segment joining the points, they form a right triangle, unless the segment is already horizontal or vertical.

The two perpendicular legs have lengths |Δx| and |Δy|. Pythagoras gives d2 = |Δx|2 + |Δy|2. Squaring removes the signs, so the absolute value bars are unnecessary inside the usual distance formula. Take the non-negative square root for the length.

Use the formula in five steps

  1. Label the endpoints (x1, y1) and (x2, y2).
  2. Subtract the x-coordinates and the y-coordinates separately.
  3. Square each difference, including any negative sign inside brackets.
  4. Add the two squared differences.
  5. Take the square root and state the length unit.

Example 1: two positive-coordinate points

Find the distance from A(1,1) to B(5,4). The changes are Δx = 5 − 1 = 4 and Δy = 4 − 1 = 3. Therefore, d = √(42 + 32) = √25 = 5 units. This is the example shown in the diagram.

Example 2: negative coordinates

Let A = (−2,−1) and B = (4,7). Subtracting a negative becomes addition: Δx = 4 − (−2) = 6 and Δy = 7 − (−1) = 8. The distance is d = √(36 + 64) = 10 units.

If you reverse the endpoints, the differences become −6 and −8. Their squares are still 36 and 64, so the distance remains 10. Keep point labels clear to make your working easy to follow.

Horizontal, vertical and zero distances

For a horizontal segment, the y-difference is zero. The formula becomes d = √[(Δx)2] = |Δx|. For example, points (−3,2) and (4,2) are 7 units apart.

For a vertical segment, the x-difference is zero, so d = |Δy|. Points (2,−4) and (2,5) are 9 units apart. If both endpoints are the same point, both differences are zero and d = 0.

Example 3: keep an exact square-root answer

Find the distance between (−1,2) and (5,8). Both coordinate changes are 6, giving d = √72 = 6√2 units ≈ 8.49 units. The simplified square root is exact. The decimal is rounded.

Do not use √(a2 + b2) = a + b; that is not a valid general simplification. Add the squared values before taking the square root.

Example 4: decimal coordinates

The points are (0.5,−1.5) and (2,0.5). Their changes are 1.5 and 2. Therefore, d = √(1.52 + 22) = √6.25 = 2.5 units. Decimal coordinates do not require a different formula.

Distance from the origin

The origin is (0,0). Substituting it as one endpoint gives d = √(x2 + y2). For example, point (−3,4) is √(9 + 16) = 5 units from the origin.

Example 5: solve for a missing coordinate

Point P is (1,2), point Q is (x,5), and PQ = 5 units. Substitute the known values and square both sides:

25 = (x − 1)2 + (5 − 2)2, so (x − 1)2 = 16. This gives x − 1 = ±4 and therefore x = 5 or x = −3.

There are two possible positions: four units to the right or four units to the left of x = 1, each with the same vertical change. An extra condition, such as Q being to the right of P, would select one answer.

Three-dimensional distance

For points (x1, y1, z1) and (x2, y2, z2), add the third squared change: d = √[(Δx)2 + (Δy)2 + (Δz)2]. This comes from applying Pythagoras in three perpendicular directions.

Example 6: points in space

Let P = (1,2,3) and Q = (4,6,15). The changes are 3, 4 and 12, giving d = √(9 + 16 + 144) = √169 = 13 units.

This is the same calculation used for a rectangular prism’s space diagonal, with the coordinate changes giving its three dimensions.

Distance, midpoint and slope are different

Distance gives the length between points. A midpoint gives the coordinates of the point halfway between them. Slope describes a line’s steepness. These questions need different formulas, even when the same two endpoints are supplied.

Units and the scale of the axes

A coordinate difference represents a length only after the scale is known. If one grid step represents 2 metres on both axes, a calculated distance of 5 grid units represents 10 metres.

Convert different axis scales or mixed physical units to a common length scale first. Do not judge distance from the picture if the axes have been stretched differently.

Common mistakes to avoid

  • Subtracting an x-coordinate from a y-coordinate instead of pairing x with x and y with y.
  • Entering a negative value without brackets before squaring it.
  • Stopping at d2 and forgetting the square root.
  • Adding the horizontal and vertical lengths as though following an L-shaped route.
  • Giving square units for a distance, or discarding a second valid missing-coordinate solution.

Try these practice questions

  1. Find the distance between (2,−1) and (8,7).
  2. Find the distance between (−4,3) and (2,3).
  3. Point A is (0,0), point B is (x,4), and AB = 5. Find the possible x-values.

Answers: 1) √(62 + 82) = 10 units. 2) 6 units. 3) x2 + 16 = 25, so x = 3 or x = −3.

Frequently asked questions

Can distance be negative?

No. Distance is non-negative. It is zero when the two endpoints coincide and positive when they differ.

Does the order of the endpoints matter?

No. Reversing the endpoints changes the signs of the coordinate differences, but squaring gives the same distance.

Does the formula work for horizontal and vertical lines?

Yes. One coordinate difference becomes zero. No division is needed, so vertical segments cause no problem.

Is distance the same as midpoint?

No. Distance is a length. Midpoint is a location, written as a coordinate pair in the plane.

Does this give road-route distance?

It gives straight-line distance in a flat Cartesian coordinate system. A road route can be longer. Latitude and longitude also need an appropriate geographical method rather than direct substitution as ordinary lengths.

For the right-triangle relationship, see the triangle formulas. Browse all Coordinates guides.

Reference texts: OpenStax, Algebra and Trigonometry 2e, section 2.1; Intermediate Algebra 2e, section 11.1; and Calculus Volume 3, section 2.2. Numerical examples, the graph and practice questions were created for this guide.

All Geometry Formulas shares clear explanations, worked examples and printable resources for learning geometry. Explore guides to shapes, angles, area, volume and coordinates. Visit our About page or report a correction.

Comments are closed.