EN RO

Distance formula: distance between two points

Enter the coordinates of the two points. The distance, the midpoint and the slope appear at once, with every step of the calculation.

Point A (x₁, y₁)
Point B (x₂, y₂)
Distance AB5
Midpoint M(2.5, 4)
Slope AB1.333

The distance formula

The distance between the points A(x₁, y₁) and B(x₂, y₂) on a plane is:

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

It comes from the Pythagorean theorem. The horizontal difference (x₂ − x₁) and the vertical difference (y₂ − y₁) are the legs of a right triangle, and the segment AB is its hypotenuse. The order of the points does not matter: the differences are squared, so the sign disappears.

In space (3D) a third term is added: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

The midpoint formula

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

The midpoint is the point halfway between A and B: the average of the coordinates on each axis. For example, the midpoint between (2, 3) and (8, 7) is (5, 5).

Worked examples

ABWorkingDistance
(1, 2)(4, 6)√(3² + 4²) = √255
(−3, 5)(2, −7)√(5² + 12²) = √16913
(0, 0)(1, 1)√(1² + 1²) = √2≈ 1.414
(2, −1)(−4, 7)√(6² + 8²) = √10010
(1, 2, 3)(4, 6, 15)√(3² + 4² + 12²) = √16913

Distance on a map: why the formula is not enough

The distance formula is exact on a flat plane. The Earth, however, is round, and latitude and longitude are angles, not metres: one degree of longitude is 111 km at the Equator but only about 77 km in central Europe. For the real distance between two cities or addresses use the distance calculator, which works on the WGS84 ellipsoid (Vincenty formula) and also shows the road distance.

Frequently asked questions

What is the distance formula?

d = √((x₂ − x₁)² + (y₂ − y₁)²). Subtract the coordinates, square the differences, add them and take the square root.

What is the midpoint formula?

M = ((x₁ + x₂)/2, (y₁ + y₂)/2) – the average of the coordinates of the two end points.

Where does the distance formula come from?

From the Pythagorean theorem: the x and y differences are the legs of a right triangle and the distance is its hypotenuse.

Can I use the distance formula with GPS coordinates?

Not directly: latitude and longitude are angles on a round Earth. For real places use the distance calculator, which works on the WGS84 ellipsoid.

See also: Distance calculator between cities · Area calculator on a map · Coordinate converter · Blog