The Distance Formula, Explained with Examples
By ToolNimba Editorial Team June 20, 2026 5 min read
The distance formula gives the straight-line distance between two points on a coordinate plane. If the points are (x1, y1) and (x2, y2), it returns the length of the segment that joins them. It is one of the most useful tools in coordinate geometry because it turns a question about a picture into a short calculation you can do by hand or with a calculator.
Quick answer
To find the distance between two points, subtract the x values, subtract the y values, square both results, add them, then take the square root. In symbols: distance = square root of [ (x2 minus x1) squared + (y2 minus y1) squared ].
The distance formula
For two points (x1, y1) and (x2, y2) in a plane, the distance d between them is the square root of [ (x2 minus x1) squared + (y2 minus y1) squared ]. The two subtractions measure the horizontal and vertical gaps between the points, and squaring then adding combines those gaps into one straight-line length.
Where the distance formula comes from
The distance formula is just the Pythagorean theorem applied to coordinates. The horizontal gap (x2 minus x1) and the vertical gap (y2 minus y1) are the two legs of a right triangle, and the distance you want is the hypotenuse. Pythagoras says the hypotenuse equals the square root of the sum of the squares of the legs, which is exactly the formula. If you can draw a right triangle between two points, you already understand the distance formula.
This connection also explains why distance is never negative. Squaring removes any minus sign from the subtractions, and the square root of a non-negative number is non-negative, so the result is always zero or greater. A distance of zero only happens when the two points are identical.
How to find the distance between two points, step by step
- Label your points so one is (x1, y1) and the other is (x2, y2). It does not matter which is which.
- Subtract the x values to get the horizontal gap, x2 minus x1.
- Subtract the y values to get the vertical gap, y2 minus y1.
- Square each of those two differences.
- Add the two squared values together.
- Take the square root of that sum. The result is the distance.
A worked example
Find the distance between (1, 2) and (4, 6).
- Horizontal gap: 4 minus 1 equals 3.
- Vertical gap: 6 minus 2 equals 4.
- Square and add: 3 squared is 9, 4 squared is 16, and 9 plus 16 is 25.
- Take the square root: the square root of 25 is 5.
So the distance is exactly 5 units. This is the classic 3, 4, 5 right triangle hiding inside the coordinates.
A worked example with negative coordinates
Negative coordinates trip people up, but the steps do not change. Find the distance between (2, 4) and (minus 1, 7).
- Horizontal gap: minus 1 minus 2 equals minus 3.
- Vertical gap: 7 minus 4 equals 3.
- Square both: minus 3 squared is 9, and 3 squared is 9.
- Add: 9 plus 9 equals 18.
- Take the square root: the square root of 18 is about 4.24 units.
Notice that minus 3 squared became positive 9. Squaring always wipes out the minus sign, which is why the order you subtract in never changes the answer.
Quick reference table
| Point A | Point B | Calculation | Distance |
|---|---|---|---|
| (1, 2) | (4, 6) | sqrt(3 squared + 4 squared) = sqrt(25) | 5 |
| (0, 0) | (3, 4) | sqrt(3 squared + 4 squared) = sqrt(25) | 5 |
| (2, 4) | (minus 1, 7) | sqrt(9 + 9) = sqrt(18) | about 4.24 |
| (minus 2, minus 3) | (4, 5) | sqrt(36 + 64) = sqrt(100) | 10 |
| (0, 0) | (x, y) | sqrt(x squared + y squared) | distance from origin |
The distance formula in 3D
The same idea extends to three dimensions. For points (x1, y1, z1) and (x2, y2, z2), the distance is the square root of [ (x2 minus x1) squared + (y2 minus y1) squared + (z2 minus z1) squared ]. You simply add a third squared difference for the z axis. For example, the distance between (5, 6, 2) and (minus 7, 11, minus 13) is the square root of (144 + 25 + 225), which is the square root of 394, about 19.85 units.
A handy special case is the distance from the origin (0, 0, 0) to any point (x, y, z), which is just the square root of (x squared + y squared + z squared). For instance, the distance from the origin to (2, 3, 6) is the square root of 49, which is exactly 7.
Common mistakes to avoid
- Squaring the coordinates instead of the differences. Always subtract first, then square the result.
- Forgetting that a negative squared is positive, which can lead to wrongly subtracting the squared terms.
- Taking the square root of each term separately. The square root applies to the whole sum, not to each piece.
- Mixing up which value is x and which is y when reading a point. Keep the pairs in order.
Where the distance formula is used
Beyond homework, the distance formula appears anywhere two positions need comparing: mapping the gap between two locations on a grid, measuring how far a game character is from a target, checking whether a point falls inside a circle, or computing error between a predicted and actual value in data work. It is also the foundation of related ideas like the midpoint formula, which finds the exact center between two points, and the slope formula, which describes the steepness of the line that joins them.
Calculate it instantly
Enter two points below and the distance calculator returns the exact distance and shows the steps.
๐ Try the free tool Distance Calculator Free distance formula calculator. Enter two points (x1, y1) and (x2, y2) to find the straight-line distance and the midpoint, with every step shown clearly.To find the point exactly halfway between two coordinates, see the midpoint formula guide. If you are brushing up on related math, our percentage guide covers another everyday calculation in the same plain-language style.
Frequently asked questions
What is the distance formula?
The distance between points (x1, y1) and (x2, y2) is the square root of (x2 minus x1) squared plus (y2 minus y1) squared. It gives the straight-line distance between the two points and comes directly from the Pythagorean theorem applied to coordinates.
How do you find the distance between two points?
Subtract the x values, subtract the y values, square both results, add the two squares together, then take the square root of that sum. The number you get is the straight-line distance between the points, measured in the same units as the coordinates.
Is the distance formula the same as the Pythagorean theorem?
Yes, it is the Pythagorean theorem written for coordinates. The horizontal and vertical gaps between the points are the two legs of a right triangle, and the distance you want is the hypotenuse, so the same square-root-of-the-sum-of-squares rule applies.
Does the order of the points matter?
No. Because each difference is squared, swapping the two points only changes the sign of the differences before squaring, and squaring removes that sign. Whether you start from point A or point B, the final distance is identical.
How do you use the distance formula with negative coordinates?
Use the exact same steps. Subtract carefully, keeping the minus signs, then square each difference. A negative number squared becomes positive, so the minus signs disappear. For example, minus 3 squared equals 9, which keeps the distance positive.
What is the distance formula in three dimensions?
For points (x1, y1, z1) and (x2, y2, z2), the distance is the square root of (x2 minus x1) squared plus (y2 minus y1) squared plus (z2 minus z1) squared. You add a third squared difference for the z axis and follow the same square-root step.
Can the distance between two points be negative?
No. Distance is always zero or positive. Squaring the differences removes any negative signs, and the square root of a non-negative number is non-negative. A distance of zero only occurs when the two points are exactly the same point.
How do you find the distance of a point from the origin?
The origin is (0, 0), so the formula simplifies to the square root of (x squared plus y squared). For example, the distance from the origin to (3, 4) is the square root of 25, which is 5. In 3D it becomes the square root of (x squared plus y squared plus z squared).