Distance Between Two Points: The Formula, Derived and Applied

October 3, 2026 · 6 min read

Two points on a plane are all you need to define a line, and the single number that summarises that line is its length. The distance formula is remarkably plain — square the gaps, add them, take the square root — but it is worth deriving, because seeing where it comes from makes it impossible to misremember.

It is Pythagoras in disguise

Take two points, A(x₁, y₁) and B(x₂, y₂). The horizontal gap between them is Δx = x₂ − x₁, and the vertical gap is Δy = y₂ − y₁. Together these two numbers are the legs of a right triangle whose hypotenuse is the straight line from A to B. Pythagoras then gives it directly:

d = √[(x₂ − x₁)² + (y₂ − y₁)²]

That is the whole formula. Everything else in this article is either a corollary or an application.

Worked example: the 3-4-5 triangle

Distance from (0, 0) to (3, 4): Δx = 3, Δy = 4.

d = √(3² + 4²) = √(9 + 16) = √25 = 5.

This is the exact case Pythagoras used 2,500 years ago, and it is the smallest whole-number right triangle — which is why it turns up so often in examples. The midpoint is (1.5, 2) and the slope is 4/3 ≈ 1.333.

Worked example with negative coordinates

Distance from (2, 5) to (8, 1): Δx = 6, Δy = −4.

d = √(36 + 16) = √52 ≈ 7.211.

Note the sign of Δy: negative because y decreased. The formula squares it, so the sign never affects the result — the distance is always positive, and that is by design. A calculator that returned −7.211 would be reporting a direction, not a distance.

The midpoint, for free

Average the coordinates:

M = ((x₁ + x₂)/2, (y₁ + y₂)/2)

The midpoint is the only point on the segment equidistant from both ends, which makes it the natural way to split a segment — the point where a journey is half done, or where a line should be hinged. The same average gives a centre of mass for two equal objects, and for unequal ones you weight the coordinates by mass instead.

Both the midpoint and the slope come out of the same two differences, Δx and Δy, which is why the distance calculator returns them together: you entered two points, and you get the segment fully described.

Extending to three dimensions

Add a third squared term:

d = √(x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²

Points (−1, 2, 3) and (4, 6, 3): Δx = 5, Δy = 4, Δz = 0, so d = √(25 + 16 + 0) = √41 ≈ 6.403.

The same pattern extends to any number of dimensions. That generality is why the formula is the backbone of 3D graphics: every vertex-to-vertex measurement in a game engine, every raycast collision test, is this formula with more terms.

Real applications

Screen sizing. A 27-inch monitor is quoted by diagonal, not width. Given a diagonal of 27 inches and a 16:9 ratio, the horizontal component of the diagonal is 16/√(16²+9²) ≈ 0.871 of it, giving a width of about 23.5 inches and a height of 13.2. That is the distance formula doing the work behind every monitor spec.

Maps and GPS. Straight-line distance between two coordinates ignores terrain and roads, so it is the optimistic bound. Once you have it, routing algorithms layer real constraints on top. The slope between two coordinates additionally gives you the bearing.

Machine vision and robotics. A camera resolving a part on a bench needs the distance from lens to part to size the field of view; a robot arm placing an item needs the distance to the target pose. Both are this formula.

Surveying. Offsetting a parallel line from a boundary is a distance calculation, and so is checking whether a proposed fence stays inside a plot.

Distance is not displacement

One distinction worth holding onto. Distance is the length of the path actually travelled; displacement is the straight line from start to end. They are equal for motion in a straight line with no reversal, and different otherwise — drive 10 km forward and 10 km back and your distance is 20 km while your displacement is zero. The velocity calculator makes the same distinction for motion over time.

Common mistakes

Adding the gaps before squaring. √(3 + 4) = 2.65, not 5. Squaring must happen inside the root.

Forgetting to square both terms. The sign of Δy does not matter, but its magnitude does — and dropping the square gives the wrong answer for any non-horizontal line.

Mixing units. If one point is in metres and the other in feet, the formula is perfectly happy to return nonsense. Convert first; the Pythagorean theorem calculator is the same idea reduced to its essentials.

Weighted midpoints and centres

For two equal objects, the midpoint is the average. For unequal ones, weight each coordinate by its mass and the formula still works:

C = (m₁x₁ + m₂x₂) / (m₁ + m₂)

Put a 70 kg person at 1.0 m from the pivot and a 20 kg person at 3.0 m and the centre of mass is (70×1.0 + 20×3.0)/90 = 130/90 ≈ 1.44 m — much closer to the heavier person, as intuition requires. This weighted average extends to any number of points, and it is the same arithmetic behind centre of gravity, moment calculations in structural work, and the k-means clustering algorithm.

Coordinates are not the only option

The formula above works in Cartesian coordinates because the axes are perpendicular and share a scale. When they are not — a map in polar or geographic coordinates — the raw formula gives the wrong answer, and you must convert first. On Earth, the distance between two latitude/longitude points is a great-circle calculation, which is why long flights follow curved routes and why a straight line drawn on a flat map is a lie near the poles.

On a plane, one further warning: the distance formula assumes a flat surface. Over a large area of the Earth's surface, curvature matters enough that the same calculation must use haversine or Vincenty formulas instead. The right answer depends on the geometry you are actually standing in.

Two points define a line — one point does not

Worth stating plainly, because it is the limit of what coordinates can tell you. A single point has infinitely many lines through it; a second point removes the ambiguity completely. Every calculation in this article follows from that: distance, midpoint and slope all become definite the moment two positions are known, and all stay ambiguous with one.

Frequently asked questions

How do I calculate the distance between two points?

Take the square root of the sum of the squared differences in each coordinate: d = √[(x₂−x₁)² + (y₂−y₁)²]. This is Pythagoras applied to the horizontal and vertical gaps.

What is the midpoint of a segment?

Average the coordinates: ((x₁+x₂)/2, (y₁+y₂)/2). The midpoint is the only point on the line segment equidistant from both endpoints.

How do I find the distance in three dimensions?

Add a third squared term: d = √[(x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²]. The same logic extends to any number of dimensions.

What is the distance formula used for in real work?

Screen and monitor sizing from diagonal and aspect ratio, map scale and GPS, vector graphics and game development, machine-vision part picking, and any robotics needing to know how far one thing is from another.

Related guides