Guide · updated 2026-09-30

How the distance between two places is calculated

Short answer

Map tools compute straight-line distance with the haversine formula: convert both latitudes and longitudes to radians, find the central angle between the points, and multiply by the Earth's radius. For the stored Boston and Providence capital points that gives 65.37 km, or 40.62 miles.

Step 1: get two coordinates

Every distance starts with two points in latitude and longitude. This site stores Boston at 42.358, -71.064 and Providence at 41.831, -71.415. North and east are positive, south and west negative, so both longitudes here are negative.

The coordinates must mean the same thing. A city has no single point, so a distance between two cities depends on which point each source picked. This site uses the state capitol coordinates stored in its state table for capitals, and the Census internal point for counties. Two sites can both be right and still differ by a mile or two because one used a city hall and the other a downtown centroid.

Step 2: the haversine formula, worked

Convert degrees to radians by multiplying by π/180. Then compute half the squared chord length between the points, called h, and turn it into the central angle c:

φ1 = 42.358° = 0.739287 rad    φ2 = 41.831° = 0.730089 rad
Δφ = -0.5270° = -0.009198 rad
Δλ = -0.3510° = -0.006126 rad
sin²(Δφ/2)                 = 2.115012e-5
cos φ1 · cos φ2 · sin²(Δλ/2) = 5.165898e-6
h = sum                     = 2.631602e-5
c = 2 · asin(√h)            = 0.01025987 rad
d = 6,371.0088 km × c       = 65.366 km = 40.616 mi

The radius 6,371.0088 km is the Earth's mean radius. Multiplying kilometers by 0.621371 gives statute miles. Try the same pair, or your own, in the calculator below the article.

The same formula on ten capital pairs

The table runs the formula on ten pairs of neighboring state capitals. Every row is computed from the stored capitol coordinates when the page is built, so a reader can check any row with the Excel formula in the questions below.

FromToKilometersMiles
Boston, MAProvidence, RI65.440.6
Albany, NYMontpelier, VT202.5125.8
Austin, TXOklahoma City, OK580.6360.8
Denver, COSalt Lake City, UT596.9370.9
Springfield, ILIndianapolis, IN298.4185.4
Sacramento, CASalem, OR718.8446.6
Atlanta, GATallahassee, FL368.3228.9
Olympia, WABoise, ID645.8401.3
Saint Paul, MNMadison, WI363.4225.8
Phoenix, AZSanta Fe, NM614.0381.5
Haversine distance on a sphere of radius 6,371.0088 km.

Why haversine and not Pythagoras

Treating latitude and longitude as flat x and y fails because a degree of longitude shrinks toward the poles. At Boston's latitude one degree of longitude is 51.2 miles, while one degree of latitude is 69.0. A flat formula would mix those two scales.

The haversine form was chosen for navigation tables because it stays accurate for small distances, where the older spherical law of cosines loses precision to rounding. Modern floating point makes either form usable, but haversine remains the common choice.

Sphere or ellipsoid?

The Earth is slightly flattened, so a sphere is an approximation. On the WGS84 ellipsoid one degree of latitude measures 110.574 km at the equator and 111.694 km near the pole, against 111.195 km everywhere on the sphere. The sphere is off by 0.56% at most on north-south legs.

Surveyors and aviation software use ellipsoidal methods such as Vincenty's or Karney's algorithms. For comparing towns, the uncertainty in where each town's point sits is larger than the sphere's error.

Four mistakes that give wrong distances

  • Forgetting radians. Spreadsheet SIN and COS expect radians. Feed them degrees and the answer is nonsense. Wrap every angle in RADIANS().
  • Dropping the minus sign. A longitude of 71 instead of -71 moves Boston to western China, and the result becomes a distance across the planet.
  • Swapping latitude and longitude. Many files store longitude first (GeoJSON does), while people usually say latitude first. Check that US latitudes fall between 18 and 72 and longitudes are negative.
  • Mixing miles. The statute mile used here is exactly 1,609.344 meters, the international definition NIST publishes. A nautical mile is longer, so a result quoted in nautical miles is a smaller number for the same trip.

Why driving distance is longer

The haversine result is the shortest path over the surface. Roads bend around terrain, water, and property, so a driving route is always at least as long and usually longer. This site gets driving distances from the Valhalla router, falls back to OSRM, and shows nothing when both fail rather than guessing a detour factor.

For flights the straight line is closer to reality, but airways, winds and approach patterns still add miles. Use the great circle route map to see the path a straight-line distance follows across a flat map.

Try it

As the crow flies distance calculator

Straight-line miles, kilometers, and nautical miles between two places, with bearings and the formula worked with your numbers.

370.9 miDenver, COSalt Lake City, UTgraticule 5° · azimuthal equidistant

Formula with your numbers

φ1 = 39.7390°   φ2 = 40.7770°
Δφ = 1.0380°   Δλ = -6.9030°
h  = sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2) = 0.00219260
c  = 2 · asin(√h) = 0.093685 rad
d  = R · c = 6,371.0088 km × 0.093685 = 596.87 km
     596.87 km × 0.621371 = 370.87 mi

Straight-line result

Miles
370.9
Kilometers
596.9
Nautical miles
322.3
Initial bearing
283.4° WNW
Final bearing
278.9° W
Midpoint
40.3093° N, 108.4100° W
Haversine on a sphere of radius 6,371.0088 km. Bearings are true north.

Questions people ask

What formula calculates distance between two coordinates?

The haversine formula: d = 2R · asin(√(sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2))), with latitudes φ and longitudes λ in radians and R the Earth's radius.

What radius should I use?

6,371.0088 km (3,958.76 miles) is the mean Earth radius used on this site. Rounding it to 6,371 km changes results by less than 2 parts per million.

Can I do this in Excel?

Yes: =2*6371.0088*ASIN(SQRT(SIN(RADIANS(lat2-lat1)/2)^2+COS(RADIANS(lat1))*COS(RADIANS(lat2))*SIN(RADIANS(lon2-lon1)/2)^2)) gives kilometers.

Why does my GPS app show a different distance?

It may measure a route instead of a straight line, use an ellipsoid instead of a sphere, or start from a different point for each place. On a short trip the ellipsoid difference is a fraction of a percent.

Sources and data as of

Data as of: computed from the formulas shown and the capital coordinates stored on this site.

  1. 01NIST: revised unit conversion factors (international foot and mile) (last verified 2026-09-30)

How every number is computed: methodology. Spotted a wrong figure? Report an error.