Home › Math & Science › Distance Formula Calculator
Distance Formula Calculator
Two points on a graph, a map grid or a game map — how far apart are they really, in a straight line? This free distance formula calculator takes the two coordinate pairs and returns the distance, and because they're the numbers everyone asks for next, the midpoint and the slope as well.
| Distance | 5 |
| Midpoint | (1.5, 2) |
| Slope | 1.3333 |
| Horizontal gap (Δx) | 3 |
| Vertical gap (Δy) | 4 |
How it works
Draw the two points on graph paper and the geometry does the rest. The horizontal distance between them (Δx) and the vertical distance (Δy) form the two short sides of a right triangle, and the straight-line distance you want is the hypotenuse. That is all the distance formula is — the Pythagorean theorem wearing coordinate clothes.
The x-coordinates say how far each point sits to the right of the origin (negative values sit to the left), and the y-coordinates say how far up (negative values are below). Which point you call "point 1" and which "point 2" makes no difference to the distance or the midpoint: the gaps are squared, so (x2 − x1) and (x1 − x2) give the same contribution. It does flip the sign of the slope calculation's two gaps together, which conveniently leaves the slope itself unchanged too.
The midpoint is the average of the two points — halfway across and halfway up — and the slope describes how steeply the line between them climbs: a slope of 1.3333 means the line rises 4 for every 3 it runs. Two honest exceptions are built in. If the points are identical, the distance is 0 and there is no line to have a slope, so the slope row says so. If the line is vertical (same x on both points), the slope is undefined, because it would mean dividing by a zero horizontal gap — the calculator reports "undefined (vertical line)" instead of a fake number.
Worked example
Find the distance between (0, 0) and (3, 4) — the classic textbook pair.
Step 1 — the gaps: Δx = 3 − 0 = 3, and Δy = 4 − 0 = 4.
Step 2 — square them: 3² = 9 and 4² = 16.
Step 3 — add and take the square root: √(9 + 16) = √25 = 5.
The calculator returns distance 5, and its two detail lines: the midpoint (1.5, 2), exactly halfway along the segment, and the slope 1.3333 (4 ÷ 3). This is the famous 3-4-5 right triangle: any pair of points separated by 3 across and 4 up is exactly 5 apart, which is a handy check whenever you use the formula by hand.
Common mistakes
Forgetting to square the gaps — or forgetting the square root. The two operations bracket the whole calculation: square, add, root. Stopping after the addition gives 25 for the example above, the squared distance, not the distance.
Mixing up which coordinates pair together. x goes with x and y goes with y. Subtracting y1 from x2 scrambles the geometry and the answer is meaningless, however tidy it looks.
Rounding the gaps before squaring. With decimal coordinates, keep full precision until the final square root. Rounding Δx and Δy to whole numbers first can move the result by far more than the display rounding at the end.
FAQ
What is the distance formula?
The distance between two points (x1, y1) and (x2, y2) is d = √((x2 − x1)² + (y2 − y1)²). It is the Pythagorean theorem in disguise: the horizontal gap and the vertical gap between the points form the two legs of a right triangle, and the distance is the hypotenuse.
How do you find the midpoint between two points?
Average the x-coordinates and average the y-coordinates: midpoint = ((x1 + x2) ÷ 2, (y1 + y2) ÷ 2). Between (0, 0) and (3, 4) the midpoint is (1.5, 2) — exactly halfway along the segment in both directions at once.
What if the two points form a vertical or horizontal line?
The distance formula still works: one of the gaps is simply zero. For a horizontal line the y-gap is 0, so the distance is just the size of the x-gap. The slope is where vertical lines break the pattern — a vertical line has an undefined slope because the x-gap is 0 and you cannot divide by it. The calculator reports that honestly instead of showing a number.
Can the coordinates be negative or decimal?
Yes. The gaps are squared in the formula, so signs take care of themselves: the distance from (−2, −1) to (1, 3) is √(3² + 4²) = 5, the same as from (0, 0) to (3, 4). Decimals work too — map coordinates and GPS-style grids are usually decimals.
Does this calculator work in 3D?
No — it covers two-dimensional points with an x and a y coordinate. The 3D version adds one more squared gap under the same square root: d = √((x2 − x1)² + (y2 − y1)² + (z2 − z1)²). If your points have a third coordinate, that is the formula to use by hand.