The distance formula calculates how far apart two points are, but the correct equation depends on the type of coordinates and space you are working with.
For two points on a standard 2D Cartesian plane, the distance formula is:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
For three-dimensional Cartesian coordinates, add the difference between the z-coordinates:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
Geographic latitude and longitude require a different method because Earth is curved. For those coordinates, a great-circle calculation such as the Haversine formula is more appropriate.
This guide explains the main distance equations, why they work, how to choose the correct one, and where to find the deeper calculator or guide for each method.
What Is the Distance Formula?
The distance formula is a mathematical equation used to find the separation between two points.
In a two-dimensional Cartesian coordinate system, let the points be:
Point 1 = (x₁, y₁)
Point 2 = (x₂, y₂)
The distance between them is:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
The formula calculates the length of the straight line connecting the two points.
It is also known as the Euclidean distance formula because it measures distance according to Euclidean geometry.
If your goal is specifically to calculate the distance between two x/y points step by step, see Distance Between Two Points.
What Do the Symbols in the Distance Formula Mean?
For:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
the symbols represent:
| Symbol | Meaning |
|---|---|
| x₁ | x-coordinate of the first point |
| y₁ | y-coordinate of the first point |
| x₂ | x-coordinate of the second point |
| y₂ | y-coordinate of the second point |
| Distance | Straight-line separation between the points |
| √ | Square root |
| ² | Square of a value |
The subscripts 1 and 2 identify which coordinate belongs to which point.
For example:
A = (2, 3)
means:
x₁ = 2
y₁ = 3
and:
B = (6, 6)
means:
x₂ = 6
y₂ = 6
How Do You Use the Distance Formula?
Use five basic steps:
- Identify the coordinates of both points.
- Subtract the x-coordinates.
- Subtract the y-coordinates.
- Square and add the differences.
- Take the square root.
For example, calculate the distance between:
A = (2, 3)
B = (6, 6)
Start with:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
Substitute the coordinates:
Distance = √[(6 − 2)² + (6 − 3)²]
Calculate the differences:
Distance = √(4² + 3²)
Square them:
Distance = √(16 + 9)
Add:
Distance = √25
Result:
Distance = 5 units
Where Does the Distance Formula Come From?
The 2D distance formula comes from the Pythagorean theorem.
For a right triangle:
c² = a² + b²
The horizontal difference between two Cartesian points is:
a = x₂ − x₁
The vertical difference is:
b = y₂ − y₁
The line joining the two original points becomes the hypotenuse:
c = Distance
Substituting these values gives:
Distance² = (x₂ − x₁)² + (y₂ − y₁)²
Taking the square root produces:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
This derivation is the standard geometric basis of the formula. Khan Academy and OpenStax likewise derive the coordinate-plane distance equation from the Pythagorean theorem.
For a deeper treatment of this specific mathematical model, see Euclidean Distance Formula.
What Is the Euclidean Distance Formula?
Euclidean distance measures the shortest straight-line separation between points in Euclidean space.
In two dimensions:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
In three dimensions:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
The same idea can be extended to additional dimensions by adding another squared coordinate difference for each dimension.
For most school geometry problems, "distance formula" usually refers to the two-dimensional version.
The dedicated Euclidean Distance Formula guide covers its properties, derivation, and applications in greater depth.
What Is the Distance Formula in One Dimension?
On a number line, distance is the absolute difference between two values.
For points x₁ and x₂:
Distance = |x₂ − x₁|
For example, find the distance between:
x₁ = 3
and:
x₂ = 11
Then:
Distance = |11 − 3|
Distance = |8|
Distance = 8
If the points are reversed:
Distance = |3 − 11|
Distance = |−8|
Distance = 8
Absolute value ensures that distance remains nonnegative.
What Is the Distance Formula in Two Dimensions?
For points:
A = (x₁, y₁)
B = (x₂, y₂)
use:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
For example:
A = (1, 2)
B = (4, 6)
Then:
Distance = √[(4 − 1)² + (6 − 2)²]
Distance = √(3² + 4²)
Distance = √(9 + 16)
Distance = √25
Distance = 5 units
For more examples involving negative values, decimals, horizontal lines, and vertical lines, see Distance Between Two Points.
What Is the Distance Formula in Three Dimensions?
For points with x, y, and z coordinates:
Point 1 = (x₁, y₁, z₁)
Point 2 = (x₂, y₂, z₂)
the distance equation becomes:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
For example:
A = (1, 2, 3)
B = (5, 5, 3)
Substitute:
Distance = √[(5 − 1)² + (5 − 2)² + (3 − 3)²]
Simplify:
Distance = √(4² + 3² + 0²)
Distance = √(16 + 9)
Distance = √25
Distance = 5 units
The third coordinate adds another perpendicular dimension to the distance calculation.
What Is the General Euclidean Distance Formula?
The same principle extends beyond two or three dimensions.
For two points with n coordinates:
P = (p₁, p₂, …, pₙ)
and:
Q = (q₁, q₂, …, qₙ)
the Euclidean distance can be written conceptually as:
Distance = √[(q₁ − p₁)² + (q₂ − p₂)² + … + (qₙ − pₙ)²]
Each additional dimension contributes another squared coordinate difference.
This generalized form is useful in fields such as data analysis, computational geometry, optimization, and machine learning, where a "point" may contain more than three variables.
Is the Distance Equation Always the Same?
No. There is no single distance equation that applies correctly to every type of problem.
The appropriate formula depends on the geometry and representation of the points.
| Problem | Appropriate distance method |
|---|---|
| Two values on a number line | Absolute difference |
| Two x/y Cartesian points | 2D Euclidean distance |
| Two x/y/z Cartesian points | 3D Euclidean distance |
| Two latitude/longitude points on Earth | Great-circle or geodesic distance |
| Two street addresses | Geocoding plus geographic or routing calculation |
| Road distance between places | Road-network routing |
| Two selected map points | Geographic coordinate calculation |
Choosing the correct model matters as much as carrying out the arithmetic correctly.
Can You Use the Distance Formula for Latitude and Longitude?
You should not normally use the ordinary 2D Euclidean formula directly on latitude and longitude values when you want real geographic distance.
Latitude and longitude describe angular positions on Earth's curved surface.
If you simply calculate:
√[(longitude₂ − longitude₁)² + (latitude₂ − latitude₁)²]
the result is an angular-coordinate separation in degrees, not automatically a meaningful distance in miles or kilometers.
For geographic coordinates, use a method designed for spherical or ellipsoidal geometry.
Our Distance Calculator uses the Haversine formula with latitude and longitude to calculate great-circle distance on a spherical Earth model.
What Is the Haversine Distance Formula?
The Haversine formula estimates the great-circle distance between two latitude and longitude points on a spherical Earth.
For two geographic points:
Point 1 = (φ₁, λ₁)
Point 2 = (φ₂, λ₂)
where φ is latitude and λ is longitude:
Δφ = φ₂ − φ₁
Δλ = λ₂ − λ₁
Then:
a = sin²(Δφ ÷ 2) + cos(φ₁) × cos(φ₂) × sin²(Δλ ÷ 2)
c = 2 × atan2(√a, √(1 − a))
Distance = R × c
where R is the assumed Earth radius.
The geographic calculator on CalculatingDistance.com currently uses:
R = 6,371 km
The full explanation belongs in our Haversine Formula guide.
Euclidean Distance vs Haversine Distance
Euclidean and Haversine distance solve different geometric problems.
| Feature | Euclidean Distance | Haversine Distance |
|---|---|---|
| Geometry | Flat | Spherical |
| Typical coordinates | x, y | Latitude, longitude |
| Main use | Cartesian geometry | Geographic distance |
| Curvature considered | No | Yes |
| Result | Straight-line planar distance | Great-circle surface distance |
Use Euclidean distance when the coordinate system behaves like a flat plane.
Use the Haversine method when you are calculating general geographic distance between latitude and longitude points on a spherical Earth model.
What Is the Formula for Distance Between Two Coordinates?
The correct formula depends on what the coordinates represent.
For Cartesian coordinates:
Point 1 = (x₁, y₁)
Point 2 = (x₂, y₂)
use:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
For geographic coordinates:
Point 1 = (latitude₁, longitude₁)
Point 2 = (latitude₂, longitude₂)
use a geographic method such as the Haversine formula.
This distinction prevents a common mistake: treating latitude and longitude as though they were ordinary x/y distances measured in miles.
What Is the Distance Calculation Formula for Speed and Time?
Distance can also be calculated from speed and time rather than coordinates.
The basic relationship is:
Distance = Speed × Time
For example, if a vehicle travels at:
60 miles per hour
for:
2 hours
then:
Distance = 60 × 2
Distance = 120 miles
This formula answers a different question from coordinate distance.
The Cartesian distance formula asks:
How far apart are these two points?
The speed-time formula asks:
How far was traveled at a given speed for a given amount of time?
For the full relationship between these quantities, see Distance, Speed and Time Formula.
How Is Distance Different From Displacement?
Distance and displacement are related but different quantities.
Distance describes how much path length has been covered.
Displacement describes the change in position from the starting point to the ending point, including direction.
For example, imagine walking:
3 miles east
and then:
3 miles west
Your total distance traveled is:
6 miles
But your final position is the same as your starting position, so the magnitude of your displacement is:
0 miles
The coordinate distance formula measures separation between positions rather than the full path traveled between them.
Can Distance Ever Be Negative?
No. Distance is nonnegative.
In the Euclidean formula, coordinate differences may be negative:
x₂ − x₁ = −4
but squaring gives:
(−4)² = 16
The final square root is also nonnegative.
For one-dimensional distance, absolute value performs the same role:
Distance = |x₂ − x₁|
Therefore:
Distance ≥ 0
A distance of zero means the two positions coincide.
Does the Order of the Points Change the Distance?
No. Distance between two Euclidean points is symmetric.
For example:
A = (2, 3)
B = (6, 6)
Calculating from A to B gives the same distance as calculating from B to A.
That is because reversing a coordinate difference changes its sign but not its square:
(6 − 2)² = 4² = 16
and:
(2 − 6)² = (−4)² = 16
Therefore:
Distance(A, B) = Distance(B, A)
Direction may change, but distance does not.
What Units Does a Distance Formula Return?
The units depend on the input system and formula.
For Cartesian coordinates measured in meters, the resulting Euclidean distance is in meters.
For coordinates measured in feet, the distance is in feet.
For abstract coordinates with no physical measurement assigned, the answer is normally reported simply as:
units
Geographic calculations are different because latitude and longitude are angular measurements. A geographic formula converts the angular relationship into a physical distance using an Earth model.
Our Distance Calculator outputs geographic distance in:
- miles;
- kilometers;
- nautical miles.
What Is the Difference Between Distance Formula and Midpoint Formula?
The distance formula tells you how far apart two points are.
The midpoint formula tells you which point lies halfway between them.
For Cartesian points:
A = (x₁, y₁)
B = (x₂, y₂)
the midpoint is:
Midpoint = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2)
For example:
A = (2, 4)
B = (8, 10)
the midpoint is:
x = (2 + 8) ÷ 2 = 5
y = (4 + 10) ÷ 2 = 7
So:
Midpoint = (5, 7)
Geographic midpoint calculations require additional care because latitude and longitude lie on a curved surface. Use our Midpoint Calculator when working with geographic coordinates.
Which Distance Formula Should You Use?
Use the coordinate system and task to select the formula.
Use Absolute Difference When
Your points lie on a one-dimensional number line.
Distance = |x₂ − x₁|
Use the 2D Euclidean Formula When
Your points are Cartesian x/y coordinates.
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
Use the 3D Euclidean Formula When
Your points include x, y, and z coordinates.
Distance = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
Use a Great-Circle Formula When
Your points are geographic latitude and longitude coordinates.
Use the Haversine Formula or our Distance Calculator for this task.
Use Routing When
You need the actual distance traveled along roads.
Use the Driving Distance Calculator instead of a straight-line mathematical formula.
Common Distance Formula Mistakes
Using the Wrong Coordinate Model
The largest conceptual error is applying a flat Cartesian formula directly to geographic latitude and longitude.
Identify what the coordinates represent before choosing the equation.
Mixing Coordinate Pairs
Always subtract corresponding coordinates:
x₂ − x₁
and:
y₂ − y₁
Do not pair x with y.
Forgetting Parentheses Around Negative Values
For:
x₁ = −3
and:
x₂ = 2
write:
2 − (−3) = 5
Forgetting to Square Both Differences
Both coordinate differences must be squared before they are added.
Forgetting the Square Root
If:
Distance² = 25
then:
Distance = 5
not 25.
Rounding Too Early
Keep intermediate calculations exact when practical and round the final answer.
Confusing Distance With Route Length
Straight-line coordinate distance does not tell you how far a car, pedestrian, or aircraft will actually travel.
Distance Formula Examples at a Glance
| Problem | Formula | Result |
|---|---|---|
| Distance from 3 to 11 | |11 − 3| | 8 |
| (1, 2) to (4, 6) | √[(4 − 1)² + (6 − 2)²] | 5 |
| (−3, −1) to (2, 3) | √[(2 + 3)² + (3 + 1)²] | √41 ≈ 6.40 |
| (1, 2, 3) to (5, 5, 3) | √(4² + 3² + 0²) | 5 |
For an interactive x/y calculation, use the Distance Formula Calculator.
For latitude and longitude, use the Distance Calculator.
Distance Formula Summary
The term distance formula can refer to several equations, depending on the geometry of the problem.
For one-dimensional values:
Distance = |x₂ − x₁|
For 2D Cartesian coordinates:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
For 3D Cartesian coordinates:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
For geographic latitude and longitude:
Use a great-circle or geodesic distance method rather than the ordinary Cartesian formula.
The key is to identify the type of coordinates before choosing the equation.
Frequently Asked Questions
What is the basic distance formula?
For two Cartesian points (x₁, y₁) and (x₂, y₂), the basic 2D distance formula is:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
It gives the straight-line Euclidean distance between the points.
What is the distance equation derived from?
The standard 2D distance equation is derived from the Pythagorean theorem. The horizontal and vertical coordinate differences form the legs of a right triangle, and the distance between the points is its hypotenuse.
What is the formula of distance in physics?
When speed is constant over the time interval, distance traveled can be calculated as:
Distance = Speed × Time
This is different from the coordinate geometry distance formula. See Distance, Speed and Time Formula for that relationship.
How do you calculate distance between two coordinates?
For Cartesian coordinates, use the Euclidean distance formula. For latitude and longitude, use a geographic distance method such as the Haversine formula because Earth's curvature affects the calculation.
Is the distance formula the same as the midpoint formula?
No. The distance formula calculates how far apart two points are, while the midpoint formula calculates the point halfway between them.
Can the distance formula give a negative result?
No. Distance is always nonnegative. Squaring coordinate differences or taking an absolute value ensures that the final distance cannot be negative.
Can I use the distance formula for GPS coordinates?
Use a geographic distance formula rather than the ordinary 2D Cartesian formula for GPS latitude and longitude. The Distance Calculator performs a spherical Haversine calculation for this purpose.
