Skip to content

Distance Calculator

Creator

Muhammad Javaid Iqbal, Lead AI Engineer

Reviewer

Muhammad Awais, Startup Mentor
Updated

2D Distance Calculator

Point 1

Point 2

(x1, y1)(x2, y2)

3D Distance Calculator

Point 1

Point 2

xyz(x1, y1, z1)(x2, y2, z2)

Distance Based on Latitude and Longitude

Point 1

Point 2

AB

Distance on Map

Click anywhere on the map for point A, click again for point B, and click a third time to move point B without starting over.

Point A

Not set

Point B

Not set

This distance calculator finds the straight-line distance between two points in a 2D plane or 3D space, and the great-circle, as-the-crow-flies distance between two latitude and longitude coordinates, either typed in or clicked on a map. The 2D, 3D, and Distance Based on Latitude and Longitude calculators show a result once you press Calculate; the Distance on Map calculator updates live as you click.

Nothing is uploaded anywhere: every coordinate and every map click stays in your browser, and the formula used for each calculator is shown next to its result rather than hidden behind the calculator.

The distance formula in 2D, and the Pythagorean theorem

The equation for distance between two points on a flat plane, also called the distance formula, is an application of the Pythagorean theorem. Take two points, (x1, y1) and (x2, y2). The horizontal gap between them, x2 minus x1, and the vertical gap between them, y2 minus y1, form the two legs of a right triangle. The straight-line distance between the points is the hypotenuse of that triangle, so the same a² + b² = c² relationship applies, rearranged into the distance formula. That rearrangement is how to find distance between any two coordinates in the 2D Distance Calculator above: enter both points, press Calculate, and the calculator applies this same equation.

distance = √((x_2 - x_1)^2 + (y_2 - y_1)^2)

Worked example. Take the points (0, 0) and (3, 4). The horizontal leg is 3 minus 0, which is 3. The vertical leg is 4 minus 0, which is 4. Squaring and adding those legs gives 3² + 4² = 9 + 16 = 25, and the square root of 25 is exactly 5. That 3-4-5 relationship is the classic right triangle used to introduce the Pythagorean theorem in the first place, and it is exactly what the 2D Distance Calculator above computes when you enter those same four numbers and press Calculate.

Extending the formula into three dimensions

The 3D version of the formula, sometimes searched as the distance formula in 3 space, adds one more axis, z, for depth, alongside x and y. Each point becomes (x1, y1, z1) and (x2, y2, z2), and the formula gains one more squared difference under the square root:

d = √((x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2)

Geometrically, this is the same right-triangle idea applied twice: once to reach the point directly below or above the target in the xy-plane, and once more using that intermediate distance and the z difference as the two legs of a second right triangle.

Worked example. Take the points (0, 0, 0) and (2, 3, 6). The three differences are 2, 3, and 6. Squaring and adding them gives 2² + 3² + 6² = 4 + 9 + 36 = 49, and the square root of 49 is exactly 7. Enter those same six numbers into the 3D Distance Calculator above, press Calculate, and the calculator returns the same clean answer.

Great-circle distance between two coordinates: the haversine formula

Use the Distance Based on Latitude and Longitude calculator to type two latitude and longitude points, or the Distance on Map calculator to click them directly on an interactive map. Enter latitude and longitude for point 1 and point 2 and press Calculate, or click once on the map for point A and again for point B. The Distance Based on Latitude and Longitude calculator shows its answer after Calculate is pressed, and the Distance on Map calculator updates immediately after each click, both in kilometers or miles using the haversine formula for great-circle distance across the Earth's surface, the distance travelled “as the crow flies”. Unlike the 2D Distance Calculator and 3D Distance Calculator above, latitude and longitude describe a real position on Earth, so this result is a genuine geographic distance rather than an abstract coordinate-plane one. In other words, these two calculators work as an as the crow flies distance calculator, or simply a crow flies distance calculator, whenever the straight-line figure between two real places, not a driving route, is what is needed.

Worked example. New York City sits at roughly 40.7128°N, 74.0060°W, and London at roughly 51.5074°N, 0.1278°W. Entering those four numbers into the Distance Based on Latitude and Longitude calculator and pressing Calculate returns a great-circle distance of about 5,570 kilometers, or 3,461 miles. That is the shortest possible path between the two cities if travel could go in a straight line through the air, not the distance a flight actually covers once real routes, wind and airspace are taken into account. Checked the other way, London to New York returns the same 5,570 kilometers, since great-circle distance does not depend on direction. A plain distance from NYC search almost always means exactly this: the distance to some other named city, which is what the Distance Based on Latitude and Longitude and Distance on Map calculators above work out for any two places you pick, not only London.

Latitude must fall between -90 and 90 degrees and longitude between -180 and 180 degrees, and the calculator rejects a value outside that range rather than returning a distance computed from a coordinate that cannot exist. Southern latitudes and western longitudes are entered as negative numbers, exactly as negative coordinates work in the 2D Distance Calculator and 3D Distance Calculator above. The most common mistake in this calculator is swapping latitude and longitude, since both are just plain numbers and a swapped pair does not always trigger that range check, for example 40 is a valid value for either one, so the result can look plausible while describing the wrong pair of points entirely.

Finding distance with the interactive map in this distance calculator

The Distance on Map calculator uses the same haversine formula, applied to two points you click instead of type, working as a distance between two points map rather than a form to fill in. The first click places point A, the second places point B, and every click after that moves point B, so a point can be adjusted without starting over. Both points’ coordinates appear underneath the map next to the distance between them, which is a fast way to check how far apart two visible places are, such as two cities, without knowing either one’s exact latitude and longitude in advance. It is still the same great-circle distance described above, not a driving route, so it will read lower than an actual road trip between the same two points.

Nothing about a click leaves your browser. The map tiles come from OpenStreetMap, but the two points you place and the distance calculated between them are never sent anywhere, the same privacy guarantee as the other three calculators.

Great-circle distance is not driving distance

This is worth stating plainly now that two of the four calculators compute real geographic distance. The Distance Based on Latitude and Longitude and Distance on Map calculators return the great-circle distance between two points on Earth, close to the measurement airlines and shipping routes are planned around at a large scale, not the distance a person would actually drive, walk or fly door to door. A road has to curve around mountains, coastlines, other buildings and the road network itself, so it is essentially always longer than the straight-line figure this calculator returns. Boston to New York, for example, is about 306 kilometers (190 miles) as the crow flies, shorter than the distance shown by a mapping app that is routing an actual road trip. San Francisco to Los Angeles is about 559 kilometers (347 miles) the same way, again shorter than the highway distance between the two cities.

The same straight-line math applies to plenty of other well-known pairs. Austin to Houston works out to about 236 kilometers (146 miles) as the crow flies. How far is Houston from Dallas the same way? About 362 kilometers (225 miles). Houston to New Orleans comes out to roughly 512 kilometers (318 miles). Further north, Boston to DC is about 634 kilometers (394 miles), and that same Boston to NYC hop, using the common shorthand for New York City, is the same 306 kilometers (190 miles) already worked out above. Every one of those figures is the great-circle line between the two cities’ coordinates, not a driving distance, so an actual road trip between any of these pairs will read higher on a mapping app.

The 2D Distance Calculator and 3D Distance Calculator are a separate case again: they measure an abstract coordinate plane or coordinate space with no connection to any real-world location at all, which is why typing latitude and longitude into those two calculators, instead of the Distance Based on Latitude and Longitude calculator, will not produce a meaningful result. For the full derivation of the haversine formula, multiple worked examples and how it compares with more precise ellipsoidal methods, see the detailed guide on great-circle distance.

Frequently asked questions

Does this calculate real-world travel distance between two places, like driving distance?

Only partly. The 2D Distance Calculator and 3D Distance Calculator compute abstract straight-line distance on a plane or in space, with no connection to any real location. The Distance Based on Latitude and Longitude calculator and the Distance on Map calculator compute real geographic distance instead, the great-circle line between two points on Earth, using the haversine formula. None of the four calculators compute driving distance, which follows actual roads and is always longer than the straight-line figure shown here.

What is the difference between the 2D and 3D formula?

The 2D formula measures distance across a flat plane using two coordinates per point, x and y. The 3D formula adds a third coordinate, z, for depth, and simply adds one more squared difference under the square root. Both formulas are the same idea, the 3D version is just the 2D version extended by one more dimension. Two identical points, in either calculator, correctly return a distance of 0 rather than an error.

How is the distance formula related to the Pythagorean theorem?

Directly. The horizontal gap between two points and the vertical gap between them form the two legs of a right triangle, and the straight-line distance between the points is the hypotenuse of that triangle. The distance formula is just a² + b² = c² rewritten with the legs as coordinate differences and solved for c.

What is the haversine formula, and how is it different from the 2D and 3D formulas above?

The haversine formula computes great-circle distance: the shortest path between two latitude and longitude points measured along the curved surface of the Earth, not through it. The 2D and 3D formulas measure a straight line through flat space instead, the right tool for coordinate geometry, graphics or physics problems, but the wrong one for two real-world locations, since the Earth's surface is curved rather than flat. Both kinds of formula still square differences and take a square root somewhere inside them, they just start from a different geometric assumption.

How do I use the map to measure the distance between two points?

Use the Distance on Map calculator and click anywhere to place point A, then click a second time to place point B. The straight-line, great-circle distance between them appears immediately, along with each point's coordinates, and clicking a third time moves point B if you want to try a different pair of locations without starting over.

Can coordinates be negative, including latitude and longitude?

Yes, in every calculator. In the 2D Distance Calculator and 3D Distance Calculator a negative x, y or z simply means the point sits on the other side of the axis origin. In the Distance Based on Latitude and Longitude calculator, a negative latitude is a location south of the equator and a negative longitude is a location west of the prime meridian, for example London sits close to 0° longitude while New York is a negative, western longitude. The formula squares every difference, so the sign of an individual coordinate never causes an error.

Is this the same tool as a "distance formula calculator" or "haversine formula calculator"?

Yes, all four calculators live on this one page. The 2D Distance Calculator is sometimes searched for as a 2d distance calculator or euclidean distance calculator, the 3D Distance Calculator as a 3d distance calculator, and together they cover what people mean by a distance formula calculator, a straight line distance calculator, a pythagorean distance calculator, or a shortest distance between two points calculator, since all of those names describe the same coordinate-geometry formula explained below. The Distance Based on Latitude and Longitude calculator and the Distance on Map calculator answer to just as many names: haversine formula calculator, lat long distance calculator, gps coordinates distance calculator, great circle distance calculator, distance between coordinates calculator, latitude longitude calculator, map distance calculator, and distance calculator by coordinates all point at the same great-circle result, shown in kilometers or miles as a distance calculator km and miles output. None of the four calculators are a flight distance calculator in the sense of tracking an actual flight path or airline route; they compute the straight-line distance between two coordinates, which is the closest simple estimate of a flight or shipping distance rather than the real routed one.

Is distance "as the crow flies" the same as flight or shipping distance?

It is the closest simple estimate of it, not an exact match. Airlines and container ships plan long routes close to the great-circle path this calculator computes, because it is the shortest possible distance between two points on a sphere, but real flight paths bend around restricted airspace, weather and airport approach patterns, and shipping lanes follow safe water rather than a literal straight line. Expect the real distance travelled to be somewhat longer than the great-circle figure, not shorter.

What is the distance formula?

In the 2D Distance Calculator and 3D Distance Calculator, the distance formula is the square root of the sum of the squared differences between two points' coordinates, the Pythagorean theorem rearranged to solve for the hypotenuse. In the Distance Based on Latitude and Longitude calculator and the Distance on Map calculator, real-world coordinates curve around a sphere rather than sitting on a flat plane, so the equivalent tool is the haversine formula instead, which swaps flat coordinate differences for latitude and longitude differences and accounts for the Earth's curvature along the way. Both are, at heart, the same question: what is the straight-line distance between these two points, just answered on a flat plane in one case and on a curved surface in the other.

Related tools: Right Triangle Calculator, Binary Calculator and Factor Calculator. More are grouped under Math Calculators, and every tool on the site is listed at all calculators.