Resources · Education
Distance Formula
The distance formula finds the straight-line distance between two points on a coordinate plane. It is one of the most useful formulas in geometry and shows up everywhere from school math to GPS to game programming. The formula is also a direct application of the Pythagorean theorem, just dressed up in coordinate notation. For a fast computed answer on any two points, the distance formula calculator takes the four coordinates and returns the distance with a step-by-step breakdown.
7 min read
What is the distance formula?
The distance formula gives the straight-line distance between two points (x₁, y₁) and (x₂, y₂) on a coordinate plane. It is one short equation that returns a single number: the length of the line segment connecting the two points.
The formula always returns a non-negative result. A distance of zero means the two points are the same. Anything larger means the points are different, and the bigger the result, the further apart they are.
When do you use the distance formula?
Use the distance formula whenever you have two points expressed as coordinates and want to know how far apart they are. Common situations:
- School geometry problems involving coordinate planes.
- Plotting points on a graph and finding the length of a segment between them.
- Game programming: distance between two characters or objects.
- GPS-style calculations over short distances.
- Engineering, physics, or any context where you have x-y coordinates and need a magnitude.
If your two points happen to lie on the same horizontal or vertical line, you do not strictly need the formula. Just subtract the differing coordinate. But the distance formula handles that case correctly too, so there is no harm in always reaching for it.
The distance formula
The formula has been written down in essentially this form since the rise of analytic geometry, and it works for any pair of points on a coordinate plane.
The distance formula
d = √((x₂ − x₁)² + (y₂ − y₁)²)
The parts
- Horizontal change = x₂ − x₁
- Vertical change = y₂ − y₁
- Distance = square root of (horizontal change squared + vertical change squared)
The two squared differences capture how far apart the points are horizontally and vertically. Adding them gives the square of the distance, and the square root brings the answer back into the same units as your coordinates.
What x₁, y₁, x₂, and y₂ mean
The coordinates label the two points:
- x₁ and y₁ are the coordinates of the first point.
- x₂ and y₂ are the coordinates of the second point.
- (x₁, y₁) reads as “x sub 1, y sub 1.” The subscript just labels which point this is.
The numbering is purely a label. You can call either point “point 1” and the other “point 2,” and the formula gives the same answer. That is because the differences (x₂ − x₁) and (y₂ − y₁) get squared, which removes any sign.
For example, the points (3, 4) and (6, 8):
- Point 1 → point 2: differences 3 and 4, squares sum to 25, distance = 5.
- Point 2 → point 1: differences −3 and −4, squares still sum to 25, distance = 5.
Why the distance formula works
The distance formula comes directly from the Pythagorean theorem. If you draw the two points on a coordinate plane and connect them with a line, you can also drop a horizontal and vertical line from one to the other to form a right triangle.
- The horizontal leg has length |x₂ − x₁|.
- The vertical leg has length |y₂ − y₁|.
- The line connecting the two points is the hypotenuse.
The Pythagorean theorem says a² + b² = c² for any right triangle. Plug in the legs and the hypotenuse:
(x₂ − x₁)² + (y₂ − y₁)² = d²
Take the square root of both sides and you have the distance formula:
d = √((x₂ − x₁)² + (y₂ − y₁)²)
The squaring step also has a useful side effect: it removes any negative signs from the legs, since lengths are always non-negative. For more on the Pythagorean theorem itself, see the Pythagorean theorem calculator.
Step by step distance formula example
Take the points (1, 2) and (4, 6).
- Identify the coordinates: x₁ = 1, y₁ = 2, x₂ = 4, y₂ = 6.
- Subtract x: x₂ − x₁ = 4 − 1 = 3.
- Subtract y: y₂ − y₁ = 6 − 2 = 4.
- Square both: 3² = 9, 4² = 16.
- Add the squares: 9 + 16 = 25.
- Take the square root: √25 = 5.
The distance is 5. You can verify this against the classic 3-4-5 right triangle: a horizontal leg of 3 and a vertical leg of 4 do form a hypotenuse of 5.
Example 1: Distance between two positive points
Take the points (0, 0) and (3, 4).
- x₂ − x₁ = 3 − 0 = 3
- y₂ − y₁ = 4 − 0 = 4
- d = √(3² + 4²) = √(9 + 16) = √25 = 5
The distance is 5. This is the classic 3-4-5 triangle.
Example 2: Distance with negative coordinates
Take the points (−2, 3) and (4, −5).
- x₂ − x₁ = 4 − (−2) = 6
- y₂ − y₁ = −5 − 3 = −8
- d = √(6² + (−8)²) = √(36 + 64) = √100 = 10
The distance is 10. The negative sign on −8 disappears when the difference gets squared.
Example 3: Distance with decimals
Take the points (1.5, 2) and (4.5, 6).
- x₂ − x₁ = 4.5 − 1.5 = 3
- y₂ − y₁ = 6 − 2 = 4
- d = √(3² + 4²) = √25 = 5
Even with decimal inputs, the distance can come out to a clean integer when the differences happen to fall on whole numbers.
For points that produce a non-integer distance, the answer often involves a square root that does not simplify to a nice number. For example, the distance between (0, 0) and (1, 1) is √2, which is approximately 1.4142.
Common distance formula mistakes
A few traps that catch people:
- Forgetting to square the differences. The formula squares both (x₂ − x₁) and (y₂ − y₁). Skipping that step gives a meaningless result.
- Adding before squaring. The formula squares each difference first, then adds. Squaring (a + b) gives a different number than squaring a and b separately and adding.
- Forgetting the square root at the end. Without the square root, you get the squared distance d², not the distance.
- Sign errors with negative coordinates. Negative coordinates require careful subtraction. 4 − (−2) is 6, not 2. The squaring step recovers the right magnitude, but only if you got the difference right.
- Treating distance as negative. Distance is always zero or positive. The formula will never return a negative number.
Distance formula calculator vs solving by hand
Solving by hand:
- Forces you to think through the steps and notice errors.
- Useful for understanding what the formula is doing.
- Slower for ugly coordinates (decimals, large or small numbers).
- Easy to slip on signs, especially with negative coordinates.
Using a calculator:
- Fast: enter the four coordinates and read the answer.
- Handles edge cases (negative coordinates, decimals, very small or large numbers).
- Reports the breakdown (Δx, Δy, squared sum) so you can see what happened.
- Shows the exact radical form when the answer does not land on a clean integer.
For the calculator approach, the distance formula calculator handles all of that in one step and shows a step-by-step breakdown using your actual numbers. For the related companion concept (the center point of the same segment rather than its length), see Midpoint Formula.
Quick summary
- Formula: d = √((x₂ − x₁)² + (y₂ − y₁)²)
- Works for any two points on a coordinate plane.
- The horizontal and vertical changes form the legs of a right triangle whose hypotenuse is the distance.
- Negative coordinates work fine; the squaring step removes any signs.
- Distance is always zero or positive, never negative.
- The formula is the Pythagorean theorem in coordinate dressing.
- The distance formula calculator runs the math in one step and shows the breakdown.
Run the numbers
Three Education math calculators that lean on the same ideas: the distance formula and its Pythagorean origin, plus the quadratic formula for any equation that needs solving on the side.
Distance Formula Calculator
Find the distance between any two points with a step-by-step breakdown and exact radical form.
Pythagorean Theorem Calculator
Solve right triangles for the missing side using a² + b² = c².
Quadratic Formula Calculator
Solve any quadratic equation with the discriminant, root type, and step-by-step breakdown.
Frequently asked questions
The distance formula is d = √((x₂ − x₁)² + (y₂ − y₁)²). It returns the straight-line distance between two points (x₁, y₁) and (x₂, y₂) on a 2D coordinate plane. The formula comes directly from the Pythagorean theorem applied to the right triangle formed by the horizontal and vertical changes between the points.
Subtract the x-coordinates to get the horizontal change. Subtract the y-coordinates to get the vertical change. Square both differences, add the squares together, and take the square root. The result is the distance between the points.
x₁ and y₁ are the coordinates of the first point. x₂ and y₂ are the coordinates of the second point. The numbered subscripts just label which point is which. The formula gives the same answer regardless of which point you call point 1, because the differences get squared.
No. Distance is always zero or positive. The formula squares the differences before taking the square root, which removes any negative sign. A distance of zero only happens when the two points are exactly the same.
Yes. Negative coordinates are fine on either or both points. The formula computes (x₂ − x₁) and (y₂ − y₁) correctly regardless of sign, and the squaring step makes both terms non-negative before they are added.
Yes. The distance formula is the Pythagorean theorem applied to coordinates. The horizontal change (x₂ − x₁) and vertical change (y₂ − y₁) form the two legs of a right triangle, and the distance between the points is the hypotenuse. So d² = (x₂ − x₁)² + (y₂ − y₁)² is just a² + b² = c² with different labels.
Yes. Decimal coordinates work the same way as integer coordinates. The differences, squares, sum, and square root are all computed at full floating-point precision. Sometimes the answer is a clean integer even with decimal inputs, when the differences happen to land on whole numbers.
For one-off calculations, doing the math by hand is fast and forces you to think through the steps. For repeated calculations or when the coordinates are messy, a calculator is faster and less error-prone. The distance formula calculator on this site runs the formula in one step and shows the breakdown so you can see what happened.