The Haversine formula calculates the great-circle distance between two latitude and longitude coordinates on a spherical Earth model.
For two geographic points, it uses their latitude difference, longitude difference, and an assumed Earth radius to estimate the shortest distance along Earth's surface.
If you already have two coordinate pairs and simply want the result, use our Distance Calculator. This guide explains the mathematics behind that calculator.
What Is the Haversine Formula?
The Haversine formula is a spherical-distance equation used to calculate the great-circle distance between two points from their latitude and longitude.
For:
Point 1 = (φ₁, λ₁)
Point 2 = (φ₂, λ₂)
where:
- φ = latitude
- λ = longitude
- R = Earth radius
first calculate:
Δφ = φ₂ − φ₁
Δλ = λ₂ − λ₁
Then:
a = sin²(Δφ ÷ 2) + cos(φ₁) × cos(φ₂) × sin²(Δλ ÷ 2)
Next:
c = 2 × atan2(√a, √(1 − a))
Finally:
Distance = R × c
The result is a great-circle distance, which represents the shortest path between the two points along the surface of the spherical model.
What Do the Symbols in the Haversine Formula Mean?
| Symbol | Meaning |
|---|---|
| φ₁ | Latitude of Point 1 |
| φ₂ | Latitude of Point 2 |
| λ₁ | Longitude of Point 1 |
| λ₂ | Longitude of Point 2 |
| Δφ | Difference between the two latitudes |
| Δλ | Difference between the two longitudes |
| R | Assumed Earth radius |
| a | Intermediate Haversine value |
| c | Central angle between the points in radians |
| Distance | Great-circle surface distance |
Latitude and longitude must be converted to radians before they are used in the trigonometric calculation.
Why Does the Haversine Formula Use Latitude and Longitude?
Latitude and longitude describe positions on Earth's curved surface.
Latitude measures angular position north or south of the Equator, while longitude measures angular position east or west of the Prime Meridian.
For example:
New York City:
Latitude = 40.7128°
Longitude = −74.0060°
Los Angeles:
Latitude = 34.0522°
Longitude = −118.2437°
These values are angular coordinates. The Haversine formula uses the angular relationship between the two positions to calculate their separation on a spherical surface.
This is fundamentally different from ordinary Cartesian coordinates such as (x, y).
For flat coordinate geometry, use the Euclidean Distance Formula instead.
Why Are Degrees Converted to Radians?
Trigonometric calculations in the Haversine formula operate on radians.
Convert degrees using:
Radians = Degrees × π ÷ 180
For example:
40° × π ÷ 180 ≈ 0.698132 radians
Your calculator performs this conversion automatically before applying sine and cosine.
You therefore enter ordinary decimal-degree latitude and longitude values rather than radians.
How Does the Haversine Formula Work?
The calculation can be understood in four stages.
1. Calculate the coordinate differences
Find the difference between the two latitudes:
Δφ = φ₂ − φ₁
and the difference between the two longitudes:
Δλ = λ₂ − λ₁
2. Calculate the Haversine value
Use:
a = sin²(Δφ ÷ 2) + cos(φ₁) × cos(φ₂) × sin²(Δλ ÷ 2)
This combines the latitude and longitude differences while accounting for their positions on a sphere.
3. Calculate the central angle
Then calculate:
c = 2 × atan2(√a, √(1 − a))
The value c represents the angular separation between the points in radians.
4. Convert the angle into distance
Finally:
Distance = R × c
where R is the assumed radius of the sphere.
The Distance Calculator on CalculatingDistance.com currently uses:
R = 6,371 km
Haversine Formula Example: New York to Los Angeles
Use these approximate coordinates:
| Location | Latitude | Longitude |
|---|---|---|
| New York City | 40.7128 | −74.0060 |
| Los Angeles | 34.0522 | −118.2437 |
Step 1: Convert the coordinates to radians
The calculator converts all four coordinate values internally using:
Radians = Degrees × π ÷ 180
Step 2: Calculate the differences
Using the coordinates above:
ΔLatitude = 34.0522 − 40.7128 = −6.6606°
ΔLongitude = −118.2437 − (−74.0060) = −44.2377°
These differences are then converted to radians.
Step 3: Calculate a
Applying the Haversine expression produces approximately:
a ≈ 0.0924109
Step 4: Calculate the central angle
c = 2 × atan2(√a, √(1 − a))
which gives approximately:
c ≈ 0.617760 radians
Step 5: Calculate the distance
Using:
R = 6,371 km
we get:
Distance = 6,371 × 0.617760
Distance ≈ 3,935.75 km
The same result is approximately:
2,445.56 miles
and:
2,125.13 nautical miles
These values match the calculation implemented in our Distance Calculator.
What Is Great-Circle Distance?
Great-circle distance is the shortest distance between two points along the surface of a sphere.
Imagine a plane cutting through the exact center of a sphere. The intersection forms a great circle.
For two points on a spherical Earth model, the shorter arc of a great circle connecting them gives the great-circle distance.
This is why the Haversine result is often called:
- straight-line geographic distance;
- direct geographic distance;
- air distance;
- as-the-crow-flies distance.
For a deeper explanation of that terminology, see As the Crow Flies Distance.
Why Not Use the Ordinary Distance Formula for Latitude and Longitude?
The standard Euclidean formula is:
Distance = √[(x₂ − x₁)² + (y₂ − y₁)²]
That formula assumes a flat Cartesian plane.
Raw latitude and longitude are angular coordinates on Earth's curved surface. Simply treating longitude as x and latitude as y does not produce a reliable geographic distance in miles or kilometers.
For example, one degree of longitude does not correspond to the same ground distance everywhere on Earth. Longitude lines converge toward the poles.
The Haversine formula accounts for the spherical geometry instead.
Use Distance Between Two Points for Cartesian coordinate calculations and the Haversine method for geographic latitude/longitude calculations.
What Earth Radius Does the Haversine Formula Use?
The formula requires an Earth-radius value because the angular distance must be converted into a physical length.
Your calculator uses:
R = 6,371 km
Once the central angle c has been calculated:
Distance = 6,371 × c
produces the result in kilometers.
If a radius is supplied in another length unit, the calculated distance is returned in that same unit.
The Earth-radius choice is also one reason the Haversine result should be understood as a spherical approximation rather than a survey-grade measurement of the ellipsoidal Earth.
How Does the Calculator Convert Haversine Distance to Miles?
Your calculator first calculates distance in kilometers.
It then uses:
Miles = Kilometers × 0.621371
and:
Nautical Miles = Kilometers × 0.539957
For example, if the Haversine result is:
3,935.75 km
then:
Miles ≈ 3,935.75 × 0.621371
Miles ≈ 2,445.56
The geographic path does not change when the unit changes. Only the numerical representation changes.
What Is the Difference Between Haversine Distance and Euclidean Distance?
The two formulas use different geometries.
| Feature | Haversine Distance | Euclidean Distance |
|---|---|---|
| Geometry | Spherical | Flat |
| Typical inputs | Latitude, longitude | x, y or x, y, z |
| Earth curvature | Included approximately | Not included |
| Typical use | Geographic coordinates | Cartesian coordinates |
| Path measured | Great-circle surface path | Straight line on a flat plane |
For the broader family of distance equations, see our Distance Formula hub.
What Is the Difference Between Haversine Distance and Driving Distance?
Haversine distance measures geographic separation. Driving distance measures a road route.
For example, two points might have a Haversine distance of 100 miles but require substantially more than 100 miles of driving because roads need to follow available connections.
Driving routes can be affected by:
- road layout;
- rivers;
- mountains;
- bridges;
- borders;
- restricted roads;
- highways and interchanges.
Use the Driving Distance Calculator when the road route is the measurement you need.
The detailed comparison is covered in Driving Distance vs Straight-Line Distance.
Is the Haversine Formula Exact?
The Haversine formula is exact for the spherical model it is given, but Earth itself is not a perfect sphere.
That distinction matters.
When we set:
R = 6,371 km
we are modeling Earth as a sphere of that radius.
The real Earth's shape is closer to an oblate ellipsoid. A calculation based on an ellipsoidal Earth model can therefore differ from a Haversine calculation.
For many ordinary geographic-distance applications, the spherical approximation is useful and computationally simple. For high-precision geodesy, surveying, or other precision-sensitive applications, an ellipsoidal method may be more appropriate.
Haversine vs Vincenty: What Is the Difference?
The main difference is the Earth model.
Haversine:
Uses a sphere.
Vincenty-type geodesic calculations:
Use an ellipsoidal Earth model.
That means an ellipsoidal method can better represent the Earth's actual geometry when higher positional precision is required.
The trade-off is additional mathematical complexity.
For a general web distance calculator, the Haversine method provides a transparent and efficient way to calculate great-circle distance from two coordinate pairs.
For professional geodesic work, the required accuracy should determine the method.
What Happens If Both Coordinates Are Identical?
The distance is zero.
If:
φ₁ = φ₂
and:
λ₁ = λ₂
then:
Δφ = 0
and:
Δλ = 0
Therefore:
a = 0
c = 0
and:
Distance = R × 0 = 0
So two identical coordinate points have a Haversine distance of:
0 km
What Happens Near the International Date Line?
Longitude values can change from close to +180° to close to −180° even when two locations are geographically close.
For example, two points might use longitudes such as:
179.5°
and:
−179.5°
Numerically, those values appear far apart if they are treated as ordinary flat x-coordinates.
A spherical trigonometric calculation handles the periodic nature of longitude much more appropriately than a simple Cartesian subtraction interpreted as ground distance.
This is another reason geographic coordinates require geographic mathematics.
What Happens Near the Poles?
Longitude lines converge at the poles.
Near a pole, large numerical differences in longitude do not necessarily represent large physical east-west distances.
The Haversine formula incorporates latitude through the cosine terms:
cos(φ₁) × cos(φ₂)
so the geographic effect of longitude varies with latitude.
An ordinary x/y interpretation of latitude and longitude does not capture this behavior correctly.
What Are Valid Latitude and Longitude Ranges?
Standard geographic latitude normally ranges from:
−90° to +90°
Longitude normally ranges from:
−180° to +180°
Examples:
40.7128, −74.0060
34.0522, −118.2437
Positive latitude represents north of the Equator and negative latitude represents south.
Positive longitude represents east of the Prime Meridian and negative longitude represents west.
The current calculator code should be updated to validate these ranges explicitly before publication.
How Is Initial Bearing Related to Haversine Distance?
Distance and bearing describe different properties of the relationship between two geographic points.
Distance tells you how far apart they are.
Initial bearing tells you the starting compass direction from Point 1 toward Point 2 along the geographic path.
Your Distance Calculator calculates both.
For the New York City to Los Angeles example, the code calculates an initial bearing of approximately:
273.69°
The current interface classifies that value as:
West
The label should ideally say Initial Direction or Initial Bearing Direction, because the bearing along a great-circle route can change after leaving the starting point.
Can the Haversine Formula Calculate Distance Between Cities?
Yes, once each city has a representative latitude and longitude.
For example:
New York City: 40.7128, −74.0060
Los Angeles: 34.0522, −118.2437
Those coordinate pairs can be entered directly into the Distance Calculator.
Remember that a city covers an area. The result therefore represents the distance between the specific coordinates selected to represent each city.
See Distance Between Two Locations for more about city and place measurements.
Can the Haversine Formula Calculate Distance Between Addresses?
Yes, but an address must first be converted into latitude and longitude.
That process is called geocoding.
After geocoding:
Address A → Latitude A, Longitude A
Address B → Latitude B, Longitude B
the Haversine formula can calculate the direct geographic distance between those coordinate points.
Our Distance Between Addresses Calculator performs both address geocoding and distance calculations.
When Should You Use the Haversine Formula?
Use the Haversine formula when:
- you have two latitude/longitude coordinate pairs;
- you need direct geographic separation;
- a spherical Earth approximation is appropriate;
- you need great-circle distance rather than road distance;
- you want a relatively simple coordinate-distance algorithm.
Typical applications include:
- GPS coordinate comparison;
- mapping;
- geographic proximity checks;
- educational geospatial calculations;
- approximate air-distance calculations;
- location-based software.
When Should You Not Use the Haversine Formula?
The Haversine formula is not the right choice for every distance problem.
Do not use it when you specifically need:
- road mileage;
- walking-route distance;
- actual flight-path distance;
- Cartesian x/y distance;
- survey-grade geodesic precision;
- travel time.
For Cartesian geometry, use the Euclidean Distance Formula.
For road travel, use the Driving Distance Calculator.
For visually selected geographic points, use the Map Distance Calculator.
Haversine Formula Summary
For two points:
Point 1 = (φ₁, λ₁)
Point 2 = (φ₂, λ₂)
calculate:
Δφ = φ₂ − φ₁
Δλ = λ₂ − λ₁
Then:
a = sin²(Δφ ÷ 2) + cos(φ₁) × cos(φ₂) × sin²(Δλ ÷ 2)
c = 2 × atan2(√a, √(1 − a))
Finally:
Distance = R × c
For the implementation used on CalculatingDistance.com:
R = 6,371 km
If you want the result without doing these calculations manually, use the Distance Calculator.
Frequently Asked Questions
What does the Haversine formula calculate?
The Haversine formula calculates great-circle distance between two latitude and longitude points on a sphere. It is commonly used to estimate direct geographic distance across Earth's surface.
What is a Haversine distance calculator?
A Haversine distance calculator applies the Haversine formula automatically to two latitude and longitude coordinate pairs. Our Distance Calculator returns the result in kilometers, miles, and nautical miles.
What Earth radius does this Haversine calculator use?
The CalculatingDistance.com implementation uses an Earth radius of 6,371 kilometers.
Does the Haversine formula account for Earth's curvature?
Yes. It models the two points on a spherical surface rather than treating latitude and longitude as flat Cartesian coordinates.
Is Haversine distance the same as driving distance?
No. Haversine distance measures direct great-circle separation. Driving distance follows roads and must be calculated with a road-routing system.
Can Haversine distance be zero?
Yes. The result is zero when both coordinate pairs identify the same point.
Can I use the Haversine formula for x/y coordinates?
No. Ordinary Cartesian x/y coordinates are better handled with the Euclidean distance formula.
Is Haversine suitable for GPS coordinates?
Yes, for general direct-distance calculations from latitude and longitude where a spherical Earth approximation is appropriate.
