Great circle distance between airports explained. What great circle distance is, the haversine formula, why it differs from actual flight distance, and how to compute it from airport coordinates using the AirLabs airports database and NearBy API.
The great circle distance is the shortest distance between two points on the surface of a sphere, measured along the surface. For two airports, it is the length of the shortest possible path between them across the curved surface of the Earth — the distance a flight would cover if it could fly a perfect, unobstructed arc from one to the other.
The name comes from geometry. A great circle is any circle drawn on a sphere whose center coincides with the center of the sphere — the equator is a great circle, as is any line of longitude paired with its opposite. The shortest path between any two points on a sphere always lies along the great circle that passes through both of them. This is why long-haul flight paths, when drawn on a flat map, appear to curve northward: they are actually following the straightest possible route over the globe, which a flat projection distorts into an arc.
For anyone working with aviation data, great circle distance is one of the most frequently needed calculations. It underpins flight-time estimation, fuel and emissions modeling, route comparison, fare-per-kilometer analysis, and any map feature that shows how far apart two airports are. It is the natural measure of "how far is it from A to B" in a domain where everything happens on a sphere.
There is an important framing point to make up front, and this article is honest about it: great circle distance between two airports is a calculation, not a stored value you fetch. What you fetch is the raw material — the precise coordinates of each airport. The AirLabs Airports Database provides those coordinates for every airport worldwide, and from them you compute the distance with a short, standard formula. This guide explains the concept, the formula, and exactly how to source the inputs from documented AirLabs endpoints.
"The Earth is a sphere, so the shortest path between two airports is an arc, not a straight line on your map. Great circle distance measures that arc. You will not download it — you will calculate it, from two pairs of coordinates and a few lines of trigonometry."
Before calculating anything, it is worth being clear about what great circle distance does and does not represent, because it is often confused with the distance a flight actually flies.
Great circle distance is the theoretical minimum — the idealized shortest arc between two airports. The distance an aircraft actually covers is almost always longer, for several real-world reasons:
So great circle distance is best understood as a baseline: the distance against which actual routings are compared. A flight that covers close to its great circle distance is flying efficiently; a large gap indicates detours. For most analytical and display purposes — estimating distances, comparing routes, modeling roughly how far apart cities are — the great circle figure is exactly the right measure, precisely because it is independent of the day-to-day variability of actual routings.
This distinction also clarifies what AirLabs data gives you. The Routes Database provides a route's typical duration in minutes — the operational flight time — but it does not provide a distance field. Distance, if you need it, is something you derive from the airport coordinates, and what you derive is the great circle figure.
The standard way to compute great circle distance from two coordinate pairs is the haversine formula. It is numerically stable for the small angles common between airports and is the formula most aviation and mapping applications use.
Given two airports with latitude/longitude in degrees — (lat₁, lng₁) and (lat₂, lng₂) — the steps are:
a = sin²(Δlat / 2) + cos(lat₁) · cos(lat₂) · sin²(Δlng / 2)
c = 2 · atan2(√a, √(1 − a))
distance = R · c
Here R is the radius of the Earth — approximately 6,371 km (or 3,959 miles if you prefer miles). The result, distance, is the great circle distance in those units.
The intuition behind it: the formula computes the central angle c subtended at the Earth's center by the two points, then multiplies that angle by the Earth's radius to get the arc length along the surface. Because it works entirely with the angular separation, it handles points anywhere on the globe, including across the date line and near the poles, without special cases.
A small caveat worth knowing: the haversine formula models the Earth as a perfect sphere, whereas the Earth is very slightly flattened (an oblate spheroid). For distances between airports this introduces an error of only a fraction of a percent — negligible for flight-time estimation, route comparison or display. Applications that need survey-grade precision use the more complex Vincenty formula instead, but for aviation distance work, haversine is the practical standard.
The haversine formula needs exactly one thing from a data source: the latitude and longitude of each airport. The AirLabs Airports Database provides these directly, and the lat and lng fields are available even on the free plan.
A single request returns an airport's coordinates along with its full metadata:
GET https://airlabs.co/api/v9/airports?iata_code=CDG&_fields=name,iata_code,lat,lng&api_key={KEY}
[{
"name": "Paris Charles de Gaulle Airport",
"iata_code": "CDG",
"lat": 49.009592,
"lng": 2.555675
}]
To compute the great circle distance between two airports, you fetch the coordinates of each — for example CDG and JFK — and feed the two pairs into the haversine formula. Using _fields=name,iata_code,lat,lng keeps the response minimal, returning only what the calculation needs.
GET https://airlabs.co/api/v9/airports?iata_code=JFK&_fields=name,iata_code,lat,lng&api_key={KEY}
[{
"name": "John F. Kennedy International Airport",
"iata_code": "JFK",
"lat": 40.639722,
"lng": -73.778889
}]
With CDG at (49.009592, 2.555675) and JFK at (40.639722, −73.778889), applying the haversine formula with R = 6,371 km yields a great circle distance of roughly 5,830 km — the baseline shortest-arc distance between Paris and New York, against which any actual transatlantic routing can be compared.
Because the Airports Database can also be queried by icao_code, city_code or country_code, you can pull coordinates for a single airport, all airports in a city group, or every airport in a country, and compute distances across any set you need.
Putting the pieces together, here is the full pattern: fetch two airports' coordinates from AirLabs, then compute the great circle distance with haversine. The example is in JavaScript, but the formula translates directly to any language.
async function getCoords(iata, apiKey) {
const url = `https://airlabs.co/api/v9/airports?iata_code=${iata}` +
`&_fields=lat,lng&api_key=${apiKey}`;
const res = await fetch(url);
const data = await res.json();
return data.response[0]; // { lat, lng }
}
function haversine(a, b) {
const R = 6371; // km
const toRad = (d) => (d * Math.PI) / 180;
const dLat = toRad(b.lat - a.lat);
const dLng = toRad(b.lng - a.lng);
const lat1 = toRad(a.lat);
const lat2 = toRad(b.lat);
const h = Math.sin(dLat / 2) ** 2 +
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLng / 2) ** 2;
return R * 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h));
}
// Usage
const cdg = await getCoords("CDG", KEY);
const jfk = await getCoords("JFK", KEY);
console.log(haversine(cdg, jfk).toFixed(0), "km"); // ~5830 km
The structure is always the same: AirLabs supplies the coordinates; haversine turns them into a distance. The same getCoords helper works for any airport in the worldwide database, so you can compute the distance between any city pair, or build a matrix of distances across many airports, from a handful of coordinate lookups.
There is one case where AirLabs computes a distance for you rather than leaving it to the haversine formula: the NearBy API. It answers a different question — "which airports are near a given point, and how far is each?" — and it returns a distance field, in kilometers, for every result, sorted nearest first.
GET https://airlabs.co/api/v9/nearby?lat=-6.1744&lng=106.8294&distance=20&api_key={KEY}
{
"airports": [{
"iata_code": "HLP",
"name": "Halim Perdanakusuma Airport",
"lat": -6.266929,
"lng": 106.891176,
"distance": 12.348
}, {
"iata_code": "CGK",
"name": "Soekarno-Hatta International Airport",
"lat": -6.127261,
"lng": 106.655808,
"distance": 19.893
}]
}
Here the distance value is the distance from the requested coordinate to each airport, already calculated. This is the right tool when the question is "what is near this location" — finding the nearest departure airport to a user, or listing all airports within a radius. The distance parameter sets the search radius in kilometers, and every returned airport (and city) carries its own distance.
It is important to be precise about the difference. NearBy gives you the distance from a point to airports around it, within a radius. It does not give you the distance between two specific named airports — for that, you use the Airports Database coordinates and the haversine formula as shown above. The two approaches are complementary: NearBy for proximity search from a location, haversine-on-coordinates for the distance between a chosen pair.
Great circle distances between airports, computed from AirLabs coordinates, feed a wide range of features:
Given the great circle distance and a typical cruise speed, applications can estimate a baseline flight time, then compare it against the operational duration from the Routes Database to see how much real routing adds. This is useful for trip planners and "how long is this flight" features.
Carbon and fuel estimates scale primarily with distance flown. Great circle distance provides the baseline distance input for emissions calculators, with the understanding that actual burn is somewhat higher due to routing and altitude.
Analysts comparing routes often normalize by distance — fare per kilometer, or revenue per available seat-kilometer. Computing great circle distance from airport coordinates supplies the denominator for these metrics across any set of city pairs.
Applications that draw routes on a map use the airport coordinates both to plot the endpoints and to render the great circle arc between them — the characteristic curved line on flight maps. The same lat/lng that feed the distance calculation feed the visualization.
For "find the closest airport to me" or "airports within 100 km" features, the NearBy API delivers ranked results with distances directly, no client-side calculation required.
A few patterns recur when building airport-distance features on AirLabs data:
lat/lng essentially never changes, so fetch coordinates once and cache them aggressively rather than re-requesting for every distance calculation.lat,lng (and perhaps name,iata_code) via _fields when you need coordinates purely for distance math, to keep responses tiny.If you are building a trip planner, an emissions calculator, a route-analytics tool or any feature that needs to know how far apart airports are, AirLabs provides the precise airport coordinates — and, for proximity search, ready-made distances — through documented REST endpoints.
Our Developer API allows you to create a custom experience for your users and increase the value of your product:
lat and lng for every airport worldwide — the inputs for great circle distance — available on the free plan._fields to fetch only the coordinates you need for distance math.distance field (in km) from a given coordinate, within a chosen radius.duration of a route, to compare against great circle baselines.You can try it right now without any obligation! Get a free flight API plan and see for yourself that we have exactly the data you need!
If you need more information, don't hesitate to contact us. We are always happy to chat with our customers and are sure to find a customized solution for each request.
Explore AirLabs, or create an account instantly and start using API.
Get FREE API Key