Mathwords logoMathwords

Haversine Formula — Definition, Formula & Example

The haversine formula is a trigonometric formula that gives the shortest distance between two points on a sphere, such as two cities on Earth, using only their latitudes and longitudes. That shortest path follows a great circle, not a straight line on a flat map.

The haversine of an angle is hav⁡θ=sin⁡2(θ/2)=1−cos⁡θ2\operatorname{hav}\theta = \sin^2(\theta/2) = \frac{1-\cos\theta}{2}. For points with latitudes φ1,φ2\varphi_1, \varphi_2 and longitudes λ1,λ2\lambda_1, \lambda_2 on a sphere of radius rr, the central angle θ\theta between them satisfies hav⁡θ=hav⁡(Δφ)+cos⁡φ1cos⁡φ2hav⁡(Δλ)\operatorname{hav}\theta = \operatorname{hav}(\Delta\varphi) + \cos\varphi_1\cos\varphi_2\operatorname{hav}(\Delta\lambda), and the great-circle distance is the arc length d=rθd = r\theta with θ\theta in radians.

Key Formula

d=2rarcsin⁡ ⁣(sin⁡2 ⁣(Δφ2)+cos⁡φ1cos⁡φ2 sin⁡2 ⁣(Δλ2))d = 2r\arcsin\!\left(\sqrt{\sin^2\!\left(\frac{\Delta\varphi}{2}\right) + \cos\varphi_1\cos\varphi_2\,\sin^2\!\left(\frac{\Delta\lambda}{2}\right)}\right)
Where:
  • dd = Great-circle distance between the two points, in the same units as the radius
  • rr = Radius of the sphere; for Earth, about 3,960 miles
  • φ1,φ2\varphi_1, \varphi_2 = Latitudes of the first and second points
  • Δφ\Delta\varphi = Difference in latitude: second latitude minus first latitude
  • Δλ\Delta\lambda = Difference in longitude: second longitude minus first longitude

Worked Example

Problem: Point A is at latitude 0°, longitude 0°. Point B is at latitude 60° N, longitude 90° E. Treat Earth as a sphere with radius r = 3,960 miles. Find the great-circle distance from A to B.
Step 1: Find the differences: the latitude difference is 60° and the longitude difference is 90°. Evaluate the two terms under the square root.
sin⁡2(30∘)=14,cos⁡0∘cos⁡60∘sin⁡2(45∘)=1⋅12⋅12=14\sin^2(30^\circ) = \tfrac{1}{4}, \qquad \cos 0^\circ \cos 60^\circ \sin^2(45^\circ) = 1 \cdot \tfrac{1}{2} \cdot \tfrac{1}{2} = \tfrac{1}{4}
Step 2: Add the terms, take the square root, and find the central angle. The arcsine of the square root of one-half is 45°.
θ=2arcsin⁡ ⁣(14+14)=2arcsin⁡ ⁣(22)=2(45∘)=90∘=π2\theta = 2\arcsin\!\left(\sqrt{\tfrac{1}{4} + \tfrac{1}{4}}\right) = 2\arcsin\!\left(\tfrac{\sqrt{2}}{2}\right) = 2(45^\circ) = 90^\circ = \tfrac{\pi}{2}
Step 3: Multiply the radius by the central angle in radians to get the arc length.
d=rθ=3960⋅π2=1980π≈6,220 milesd = r\theta = 3960 \cdot \tfrac{\pi}{2} = 1980\pi \approx 6{,}220 \text{ miles}
Answer: The great-circle distance is exactly 1980π miles, or about 6,220 miles. The two points are a quarter of the way around Earth from each other.

Why It Matters

GPS apps, flight-planning software, and shipping logistics use the haversine formula to compute distances between coordinates. Programmers prefer it to the spherical law of cosines because it stays accurate for very short distances. With the cosine version, a computer can lose precision when the cosine of a tiny angle rounds to almost exactly 1.

Common Mistakes

Mistake: Multiplying the radius by the central angle in degrees. In the example above, this gives 3,960 × 90 = 356,400 miles, which is more than Earth's circumference.
Correction: The arc length formula d = rθ requires θ in radians. Convert first: 90° = π/2, so d = 3,960 × π/2 ≈ 6,220 miles.

Related Terms