Skip to main content
Distance Formula

Distance Formula Calculator

Calculate distance between two points on a coordinate plane using the distance formula.

Point 1

Point 2

Enter two coordinate points to calculate distance, midpoint, and slope

How It Works

The distance between two points in a 2D coordinate plane is the length of the straight line that joins them. This calculator takes two points, (xโ‚, yโ‚) and (xโ‚‚, yโ‚‚), and returns that straight-line distance, along with two closely related results: the midpoint(the exact centre of the segment) and the slope (how steeply the line rises or falls). It is designed for students learning coordinate geometry, for teachers building worked examples, and for anyone in surveying, design, mapping, or programming who needs a quick, reliable answer without hand-calculating square roots.

The distance formula is one of the most widely used results in all of mathematics because it is a direct application of the Pythagorean theorem. Picture the two points as opposite corners of a right-angled triangle: the horizontal gap and the vertical gap form the two legs, and the distance you want is the hypotenuse. Squaring each leg, adding them, and taking the square root gives the length of that hypotenuse โ€” which is exactly the distance between the points.

Formulas

Distance: d = โˆš((xโ‚‚โˆ’xโ‚)ยฒ + (yโ‚‚โˆ’yโ‚)ยฒ)

Midpoint: M = ((xโ‚+xโ‚‚)/2, (yโ‚+yโ‚‚)/2)

Slope: m = (yโ‚‚โˆ’yโ‚) / (xโ‚‚โˆ’xโ‚)

The horizontal difference xโ‚‚โˆ’xโ‚ is often written as ฮ”x ("change in x") and the vertical difference yโ‚‚โˆ’yโ‚ as ฮ”y. Because both differences are squared in the distance formula, the order in which you subtract the points does not matter โ€” a negative difference becomes positive once squared, so distance is always zero or positive. The slope, however, does depend on direction: a positive slope rises from left to right, a negative slope falls, and a slope of zero is a flat, horizontal line. When xโ‚ = xโ‚‚ the line is vertical, the denominator becomes zero, and the slope is undefined.

Worked example

Take the points (1, 2) and (4, 6). The horizontal gap is ฮ”x = 4 โˆ’ 1 = 3 and the vertical gap is ฮ”y = 6 โˆ’ 2 = 4. The distance is d = โˆš(3ยฒ + 4ยฒ) = โˆš(9 + 16) = โˆš25 = 5. The midpoint is ((1+4)/2, (2+6)/2) = (2.5, 4), and the slope is (6โˆ’2)/(4โˆ’1) = 4/3 โ‰ˆ 1.33. This is the famous 3-4-5 right triangle hiding inside the coordinate plane. Enter these four values in the fields above and you will see the same results, with the step-by-step working revealed on demand.

Tips for using this calculator

You can enter negative coordinates and decimals โ€” points in the second, third, or fourth quadrant work exactly the same way. If you only care about distance, you can ignore the midpoint and slope outputs; they are provided for convenience. Sketching the two points on graph paper first is a great habit: it gives you a rough idea of the answer so you can sanity- check the calculator, and it makes the right-triangle reasoning behind the formula obvious.

Where the distance formula is used

Although it looks like a piece of pure textbook geometry, the distance formula sits at the heart of many everyday technologies. Mapping and navigation apps use it (and its spherical cousin, the haversine formula) to estimate how far apart two locations are. Video games and computer graphics rely on it constantly for collision detection โ€” deciding whether two objects are close enough to touch. In data science it appears as the Euclidean distance, the default way of measuring how similar two data points are in clustering methods such as k-means and in nearest-neighbour algorithms. Surveyors, architects, and engineers use it to work out the true length of a sloped run from its horizontal and vertical components. Seeing the same formula recur across these fields is a good reminder that the Pythagorean theorem is one of the most practical results you will ever learn.

Common mistakes to avoid

The most common error is forgetting to square the differences before adding, or taking the square root of the parts separately โ€” note that โˆš(aยฒ+bยฒ) is not the same as a + b. Another frequent slip is mixing up the coordinates of the two points; always pair x with x and y with y. Finally, remember that a vertical line has an undefined slope (not a slope of zero) โ€” zero slope belongs to horizontal lines.

Frequently Asked Questions

The distance formula d = โˆš((xโ‚‚โˆ’xโ‚)ยฒ + (yโ‚‚โˆ’yโ‚)ยฒ) comes from the Pythagorean theorem. The horizontal difference (xโ‚‚โˆ’xโ‚) and vertical difference (yโ‚‚โˆ’yโ‚) form the legs of a right triangle, and the distance is the hypotenuse.

Part of Geometry Calculators โ€” compare every related calculator in one place.