Distance Calculator
Calculate the distance between two points in 2D or 3D with the Euclidean distance formula, or the great-circle distance between two latitude and longitude points in km, miles, or nautical miles.
https://hexacalculator.com/calculators/mathematics/arithmetic/distance-calculator
Mathematics
Arithmetic
Distance Calculator
Calculate the distance between two points in 2D or 3D with the Euclidean distance formula, or the great-circle distance between two latitude and longitude points in km, miles, or nautical miles.
Distance Calculator
Show the midpoint of the two points
The point exactly halfway between point 1 and point 2.
Show how each axis builds the distance
A bar chart of each axis's squared difference, which add up to the distance squared.
Enter the X and Y values for both points (and Z too in 3D). The distance appears as soon as both points are complete.
Please input values into the fields
Was this calculator helpful?
It takes one click and shapes what we fix next.
Add as preferred on GoogleThis distance calculator allows you to find the distance between two points in several ways. You can calculate the 2-dimensional (2D) distance between two coordinates, the 3-dimensional (3D) distance through space or the great circle distance which is derived from the longitude and latitude information of both points on Earth. Select a mode, enter the two points and the result will be shown instantly.

The straight-line distance between two points is the Euclidean distance, which is directly derived from Pythagoras' theorem. For distances along the surface of Earth, the Haversine formula on a sphere is used. The following explains these methods with examples.

Distance formulae
2D distance.
The distance between two points on a plane is the square root of the sum of squares of differences of their x and y coordinates.

The coordinates of the first point are x1 and y1, while the coordinates of the other point are x2 and y2. Since squaring each difference ensures that the result is not negative, it does not matter which point is considered "first". The distance from point 1 to point 2 is the same as the distance from point 2 back to point 1.
3D distance
In a three-dimensional space the formula is extended to include the z-axis term which corresponds to two applications of the Pythagorean theorem.
If the Z-values of both points are equal, then the extra term becomes zero and the formula reduces to the 2D distance version. The 2D distance mode works exactly like that, measuring only distances in the X and Y directions.
Calculating great-circle distance from latitude and longitude
The distance between two points on Earth is measured along the surface of the Earth, not through it. The shortest path along this surface is called a great circle distance and can be calculated from the latitude and longitude of the two points using the haversine formula.
where r is the radius of the Earth (roughly 6371 km). Both latitudes are designated by the Greek letter phi and both longitudes by lambda, with all values given in radians. A great circle is the largest circle that can be drawn on a sphere. The short arc of the great circle between two points represents the shortest path over the Earth's surface, i.e. the route an airplane would typically follow.
Instructions for using this calculator:
Select the mode from above. In Mode 2 you enter the X and Y coordinates of each point. In Mode 3 there is also a field for Z. For points on Earth switch to Longitude and Latitude mode and enter each coordinate in decimal degrees. North and East are positive, South and West are negative.
Once both points are fully entered, the distance will be prominently displayed as the primary result, along with associated values. In coordinate mode, you can activate the center and diagram to split and display the distance along each axis. In latitude/longitude mode, results will also show a distance in miles and initial bearing from the origin point.
Examples for each mode:
In mode 2 we look at the points (1,5) and (3,2). The differences are 2 and -3, squared they become 4 and 9.

Adding them together gives us 13, and the square root of 13 is approximately 3.61.

In mode 3 we consider (1, 3, 7) and (2, 4, 8). Since the differences for each coordinate axis are all 1, the squared values are respectively 1, 1 and 1, and the distance is the square root of 3, approximately 1.73.
Let's take the two cities as examples: The coordinates for the center of Washington, D.C. are 38.8976 and -77.0366 while the coordinates for the center of Philadelphia are 39.9496 and -75.1503. Calculating with the Haversine formula, the distance between these two points is about 199.9 km or approximately 124 miles. The initial bearing on the course, calculated as a straight line along the surface of the Earth, is about 53 degrees and the true direction is north-east.
What is shown in the calculation tool:
In addition to the distance, results are broken down into their individual components and presented on a panel. What additional information is shown depends on which mode you choose.
Value | Mode | Meaning |
|---|---|---|
X / Y / Z difference | 2D, 3D | The gap on each axis (second minus first) |
Distance squared | 2D, 3D | The value under the square root |
Midpoint | 2D, 3D | The point halfway between, averaged on each axis |
Distance in miles | Lat / long | The great-circle distance in statute miles |
Initial bearing | Lat / long | The compass heading to set out on |

More examples:
Below is a list of pairs of coordinates and their straight line distance. The results are rounded to two decimal places. On the last row, Z does not change which means it's basically a 2D distance.
First point | Second point | Distance |
|---|---|---|
(0, 0) | (3, 4) | 5.00 |
(1, 2, 3) | (4, 6, 8) | 7.07 |
(-5, 2, -3) | (1, -4, 7) | 13.11 |
(2, 3, 5) | (7, 9, 5) | 7.81 |
The distance from a point to the origin is a special case that can be useful to know. It corresponds to the length of the vector when this point is considered as a vector, so it's also called the magnitude of the vector. The distance from the point (3, 4) to the origin is 5, which means that the length of this vector is also 5.
The distance on Earth's surface and the formula used:
Because the haversine formula treats the earth as a perfect sphere, it is off by up to half a percent due to the fact that the earth is actually an oblate ellipsoid. The distance across the equator is about 6,378 km while the distance from pole to pole is about 6,357 km.

If higher accuracy is required the Lambert formula calculates on an ellipsoid and reduces error to within about ten metres over thousands of kilometres. Neither formula gives exact values as there is no formula that takes into account all the hills and valleys in the earth's surface. When planning a trip, the Haversine distance given here will usually be much more accurate than actually required.
Comparison of Euclidean distance and other distances:
The linear distance returned by the coordinate mode is the Euclidean distance, which is the shortest path through space. This is not a Manhattan distance. The Manhattan distance is calculated by adding up the absolute differences instead of squaring the differences, corresponding to movement on a grid such as driving in an urban area. For moving from (1, 2, 3) to (4, 6, 8), the Euclidean distance is about 7.07 while the Manhattan distance is 3 + 4 + 5 which is 12.
The great circle distance is also different. This is the shortest path along a curved surface, not through open space. So long-haul flights on a flat map look more like arcs than straight lines.
Application areas of distance calculation
In navigation and travel the great circle distance is used to estimate flight paths, fuel consumption and travel times. In logistics and ride services it is first used to quickly calculate the straight-line distance between two points after which a route based on actual roads is planned.
The distance between coordinates is constantly used in software. Game engines check this every frame to see if a player is near checkpoints or enemies. Squared form is usually used to avoid calculating the square root. In machine learning, it's used to measure proximity between data points and forms the basis for algorithms like k-nearest neighbors and k-means clustering. In physics and robotics, it's used to calculate displacements and plan routes.
Tips for accurate results
In coordinate mode both points must use the same units for each axis. This calculator does not convert between units so using meters on one axis and feet on the other will result in nonsense values. The coordinates can be positive, negative or zero freely.
In the latitude and longitude mode you should use decimal degrees instead of degrees and minutes. For example 38 degrees, 53 minutes is 38.8833 in decimal format where the minutes are divided by 60. Southern latitudes and western longitudes must be entered as negative numbers.
Frequently asked questions
What is the formula for distance?
For two points on a plane the distance d is calculated by adding the square of the difference between x2 and x1 to the square of the difference between y2 and y1 then taking the square root of that sum. In 3D (3 dimensions) the square of the difference between z2 and z1 is also added to the square root. This is Pythagoras' theorem. Squaring each difference prevents the distance from being negative.
How to calculate distance between two points given by latitude and longitude?
Switch to the latitude and longitude mode and enter the coordinates of each point in decimal degrees. The calculator uses the Haversine formula to calculate the great circle distance, i.e. the shortest path on the surface of the Earth. The result is displayed in kilometers or miles and also includes the initial azimuth.
Is this a driving distance or straight line distance?
This is the straight-line distance, or the shortest distance between two points. In coordinate mode it shows the Euclidean distance in space while in latitude/longitude mode it shows the great-circle distance along the surface of the Earth. As neither measurement follows roads, the actual driving or flying distance will usually be longer.
Can you use negative numbers for coordinates?
Yes. In coordinate mode the individual differences are squared so that sign doesn't matter, therefore points like (-5, 2, -3) are treated just like any other point. For latitude and longitude you should use negative numbers for south latitude and west longitude.
What is the difference between Euclidean distance and Great-circle distance?
The Euclidean distance is the shortest straight line in space and what the 2D and 3D mode outputs is exactly that distance. The Great-circle distance is the shortest path along a curved surface like Earth, and what the Latitude/Longitude mode outputs is this distance. For short distances both values are quite similar but as the distance gets larger the difference becomes bigger.
How accurate is the Great Circle Distance?
The Haversine formula assumes that the Earth is a sphere, so there can be errors due to slight deviations of the surface of the Earth, which can amount to about 0.5 percent at most. However, this is accurate enough for travel planning purposes. In contrast, surveying uses formulas that take into account the ellipsoidal shape of the Earth, such as Lambert or Vincenty.
Related calculators






Disclaimer: This calculator is provided for general informational and educational purposes only. Our calculators are under active development, and results may be inaccurate, incomplete, or unsuitable for your situation. Always verify the figures independently and seek advice from a qualified professional before relying on them. We make no warranties and accept no liability for any loss or decision arising from use of this tool.
References
- Wikipedia: Euclidean distance
The distance formula in two, three, and higher dimensions, and its link to vector length.
- Wikipedia: Haversine formula
The great-circle distance between two latitude and longitude points on a sphere.
- Movable Type Scripts: Calculate distance and bearing
A reference implementation of the haversine distance and initial bearing.