The distance formula gives the length of the straight line between two points from their coordinates. It is the Pythagorean theorem in disguise: the horizontal and vertical gaps are the legs of a right triangle, and the distance is its hypotenuse. Enter two points in 2D, or switch to 3D to add a z-coordinate.
The formula is Pythagoras applied to a grid: the horizontal and vertical gaps between the points are the two short sides of a right triangle, and the distance is the long side. It works in two or three dimensions.
What is the distance formula?
The distance formula gives the straight-line (Euclidean) distance between two points from their coordinates: d = √((x₂ − x₁)² + (y₂ − y₁)²). It comes directly from the Pythagorean theorem — the horizontal change and the vertical change are the two legs of a right triangle, and the segment joining the points is the hypotenuse.
In three dimensions one more term is added under the square root: (z₂ − z₁)². The formula is used in coordinate geometry, to find the radius of a circle from its center and a point on it, in physics for displacement, and in computer graphics, mapping and machine learning wherever “how far apart” is needed on a flat grid.
How to use the distance formula calculator
- Choose 2D or 3D.
- Enter the coordinates of the first point and the second point.
- Read the straight-line distance and the gaps along each axis.
Formula
d = √((x₂ − x₁)² + (y₂ − y₁)²)
Subtract the coordinates to get the horizontal and vertical gaps, square each, add them and take the square root. In three dimensions add (z₂ − z₁)² under the root as well.
The order of the points does not matter — squaring removes any minus sign.
Worked examples
Distance between two points in 2D
- Points in
- 2D (x, y)
- x₁
- -3
- y₁
- 4
- x₂
- 5
- y₂
- -2
- Distance
- 10
- Steps
- √(8² + (-6)²) = √100
- Δx
- 8
Δx = 5 − (−3) = 8 and Δy = −2 − 4 = −6. d = √(8² + (−6)²) = √(64 + 36) = √100 = 10.
Distance in 3D
- Points in
- 3D (x, y, z)
- x₁
- 1
- y₁
- 2
- z₁
- 3
- x₂
- 4
- y₂
- 6
- z₂
- 15
- Distance
- 13
- Steps
- √(3² + 4² + 12²) = √169
- Δx
- 3
The changes are 3, 4 and 12, so d = √(9 + 16 + 144) = √169 = 13.
Distance between pairs of points
| Point 1 | Point 2 | Δx, Δy | Distance |
|---|---|---|---|
| (0, 0) | (3, 4) | 3, 4 | 5 |
| (1, 2) | (7, 10) | 6, 8 | 10 |
| (-3, 4) | (5, -2) | 8, -6 | 10 |
| (0, 0) | (1, 1) | 1, 1 | 1.4142 |
| (2, -1) | (7, 11) | 5, 12 | 13 |
| (-6, -2) | (2, 13) | 8, 15 | 17 |
| (1, 1) | (4, 5) | 3, 4 | 5 |
Straight-line distance versus walking distance
From (0, 0) to (3, 4) the straight-line distance is √(3² + 4²) = 5. On a street grid where you can only travel along the axes, the trip is 3 + 4 = 7, sometimes called the taxicab or Manhattan distance. Which one you need depends on whether you can cut across.
Common mistakes
- Forgetting to square a negative difference properly: (−6)² is +36, never −36.
- Adding the differences before squaring: (Δx + Δy)² is not Δx² + Δy².
- Stopping before the square root — Δx² + Δy² is the squared distance, not the distance.
- Using it for distances on the Earth’s surface over long ranges, where the curvature matters and a great-circle formula is needed.
- Pairing x₁ with y₂. Subtract x from x and y from y.
Frequently asked questions
How do I find the distance between two points?
Use d = √((x₂ − x₁)² + (y₂ − y₁)²). From (1, 2) to (7, 10): √(6² + 8²) = √100 = 10.
Can the distance be negative?
No. The squares are never negative, so the distance is always zero or positive. It is zero only when the two points are the same.
Is the distance formula the same as the Pythagorean theorem?
Yes. The differences in x and y are the legs of a right triangle, and the distance is its hypotenuse.
Can I use it for GPS coordinates?
Only for short distances. Latitude and longitude are angles on a curved surface, so long distances need the haversine formula instead.
Sources
- College Algebra 2e, 2.1 The Rectangular Coordinate Systems and Graphs, OpenStax, Rice University
- Distance, Wolfram MathWorld
Last updated · Calculations checked by automated tests· Editorial policy