Distance Calculator

About this calculator

The Distance Calculator finds the straight-line distance between two points on a 2D plane or in 3D space using the distance formula, with every step shown (plus the slope and angle for 2D). It also measures the distance between two places on Earth from their latitude and longitude, in kilometers and miles.

Earth distances use Lambert's formula on the WGS-84 ellipsoid, which accounts for the planet's slightly flattened shape and is accurate to within a few meters over thousands of kilometers. Coordinates can be entered as decimal degrees or as degrees, minutes and seconds.

Point 1
Point 2
Point 1
Point 2
Coordinate format
Point 1
North positive, south negative
East positive, west negative
Point 2
Latitude 1
Longitude 1
Latitude 2
Longitude 2
Embed this calculator

Paste this code into a Custom HTML block on your site. The calculator fits the width of the block. Adjust the height in the code if you want more room for results.

Find this widget in the publisher directory

Distance in a 2D coordinate plane

The distance between two points (x₁, y₁) and (x₂, y₂) on a flat plane comes straight from the Pythagorean theorem. The horizontal and vertical differences form the legs of a right triangle, and the distance is its hypotenuse:

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

Example: from (1, 1) to (4, 5), ΔX = 3 and ΔY = 4, so d = √(9 + 16) = √25 = 5. The same differences also give the slope, ΔY / ΔX = 4/3 ≈ 1.3333333333333, and the direction of travel, arctan(4/3) ≈ 53.130102354156° counterclockwise from the positive x-axis.

Distance in 3D space

Adding a third axis simply adds one more squared difference under the root:

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

Example: from (3.5, −2, 4) to (−7, 9.25, −1.5), the differences are −10.5, 11.25 and −5.5. Their squares sum to 110.25 + 126.5625 + 30.25 = 267.0625, so the distance is √267.0625 ≈ 16.342046995404. The sign of each difference does not matter because it is squared.

Distance between two points on Earth

On a globe, the shortest path between two places is not a straight line on a map but a curve along the surface. Two common ways to compute it are the haversine formula and Lambert's formula.

Haversine formula

The haversine formula treats Earth as a perfect sphere of radius R and finds the great-circle distance:

a = sin²(Δφ / 2) + cos φ₁ · cos φ₂ · sin²(Δλ / 2),   d = 2R · arcsin(√a)

Here φ is latitude and λ is longitude, both in radians. With the mean radius of about 6,371 km, the result is usually within about 0.5% of the true distance. The error comes from Earth not being a sphere: its radius is about 6,378 km at the equator and about 6,357 km at the poles.

Lambert's formula

Lambert's formula corrects for that flattening. It first converts each latitude to a reduced latitude on the WGS-84 ellipsoid (equatorial radius 6,378,137 m, flattening 1/298.257223563), computes the central angle σ between the points, then applies a correction:

d = a · (σ − (f / 2) · (X + Y))

where X and Y depend on σ and on the mean and half-difference of the latitudes. For long distances it agrees with far more complex geodesic methods to within about 10 meters, which is why this calculator uses it for the headline figure.

Worked example

From the White House (38.8976, −77.0366) to Philadelphia's Independence Hall area (39.9496, −75.1503), Lambert's formula gives about 200.0 km, or 124.3 miles. New York (40.7128, −74.006) to Los Angeles (34.0522, −118.2437) is about 3,944.4 km (2,450.9 miles), and London to Sydney is about 16,989.2 km.

Entering coordinates

Use decimal degrees with north and east positive and south and west negative, or switch to degrees, minutes and seconds and choose N/S and E/W. One minute is 1/60 of a degree and one second is 1/3600, so 38° 53' 51.36" equals 38.8976°.

Limits of the formulas

These are surface distances "as the crow flies". Driving or walking routes are longer, and flight paths vary with winds and air corridors. The 2D and 3D formulas assume flat Euclidean space, so do not use them directly on latitude and longitude values except for very short distances.

Choosing the right mode

Use the 2D mode for points on a flat drawing, map grid or graph, and the 3D mode when height or depth matters, such as in CAD models, physics problems or game coordinates. Use the latitude and longitude mode for real places on Earth; the result is the shortest route over the surface, often called the great-circle distance.

Frequently asked questions

What is the distance formula?
d = √((x₂ − x₁)² + (y₂ − y₁)²) in 2D, with an extra (z₂ − z₁)² term under the root in 3D.
How do I calculate the distance between two latitude and longitude points?
Use a great-circle method such as the haversine formula, or Lambert's formula for better accuracy on Earth's ellipsoid. Enter both coordinates above to get the result in kilometers and miles.
Is the haversine formula accurate?
It assumes a spherical Earth, so it can be off by up to about 0.5%. Ellipsoidal methods such as Lambert's formula reduce the error to meters.
Why is the flight distance different from the driving distance?
The calculator gives the shortest path over Earth's surface. Roads follow terrain and networks, so driving distances are almost always longer.

Formulas and sample results on this page were checked against independent references. Page last reviewed or updated . How we verify calculators. Project led by Shaun Connell.