Calculate the distance between two points on a graph, in 3D space, or on Earth from latitude and longitude, with the midpoint, bearing and full working.
Working
Uses the distance formula d = √((x₂ − x₁)² + (y₂ − y₁)²), which comes from Pythagoras' theorem.
A distance calculator finds the straight-line distance between two points on a 2D graph, in 3D space, or on the Earth’s surface from their latitude and longitude. For coordinates it uses the distance formula from Pythagoras’ theorem and also gives the midpoint, slope and angle. For map coordinates it uses the haversine formula to give the great-circle distance in kilometres, miles and nautical miles, along with the initial compass bearing.
For example, the distance between (1, 2) and (4, 6) is 5, the distance between (1, 2, 3) and (4, 6, 15) is 13, and the great-circle distance from New York (40.7128, −74.0060) to London (51.5074, −0.1278) is about 5,570 km, or 3,461 miles.
The distance between two points (x₁, y₁) and (x₂, y₂) on a flat plane is:
d = √((x₂ − x₁)² + (y₂ − y₁)²)
This is Pythagoras’ theorem in disguise. The horizontal change Δx and the vertical change Δy form the two shorter sides of a right triangle, and the distance between the points is the hypotenuse.
For (1, 2) and (4, 6), Δx = 4 − 1 = 3 and Δy = 6 − 2 = 4. The distance is √(3² + 4²) = √(9 + 16) = √25 = 5. When the answer isn’t a whole number, the calculator gives an exact form too: the distance from (0, 0) to (2, 2) is √8 = 2√2 ≈ 2.8284.
For (−3, 5) and (2, −7), Δx = 2 − (−3) = 5 and Δy = −7 − 5 = −12. Squaring removes the sign, so the distance is √(25 + 144) = √169 = 13. Brackets around negative numbers help avoid sign mistakes.
In 3D, add the square of the change in z:
d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
For (1, 2, 3) and (4, 6, 15), the changes are 3, 4 and 12, so d = √(9 + 16 + 144) = √169 = 13. This is used in physics, engineering, 3D graphics and game design, and for finding the space diagonal of a box: a box measuring 3 × 4 × 12 has a diagonal of 13.
The point exactly halfway between two points is found by averaging their coordinates: ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2). The midpoint of (1, 2) and (4, 6) is (2.5, 4). In 3D, average the z-coordinates as well.
In coordinate geometry, the distance formula is the main tool for checking the sides of a shape. Take the points A(0, 0), B(4, 0), C(4, 3) and D(0, 3). AB and DC both have length 4, BC and AD both have length 3, and the diagonals AC and BD are both √(16 + 9) = 5. Equal opposite sides and equal diagonals show that ABCD is a rectangle. In the same way, you can show a triangle is isosceles by finding two equal sides, or check that a point lies on a circle by confirming that its distance from the centre equals the radius.
The distance formula measures the length of a straight line, sometimes called the Euclidean distance. In a city laid out on a grid, you can’t walk through buildings, so the distance you actually travel is the sum of the horizontal and vertical moves: |x₂ − x₁| + |y₂ − y₁|. This is called the taxicab or Manhattan distance. From (1, 2) to (4, 6), the straight-line distance is 5, but the grid distance is 3 + 4 = 7. Data scientists use both measures, depending on the problem, when comparing how similar two data points are.
A related question is how far a point is from a line, measured along the perpendicular, which is the shortest path. For a line written as ax + by + c = 0 and a point (x₀, y₀), the distance is |ax₀ + by₀ + c| ÷ √(a² + b²). For the line 3x + 4y − 10 = 0 and the point (5, 5), the distance is |15 + 20 − 10| ÷ 5 = 25 ÷ 5 = 5. This formula is used in surveying, robotics and computer graphics.
The Earth is round, so the shortest route between two places follows a great circle, not a straight line on a flat map. The calculator uses the haversine formula:
Here φ is latitude and λ is longitude, both in radians, and R is the Earth’s mean radius, 6,371 km. The haversine formula stays accurate even for points very close together or on opposite sides of the world.
| Route | Approximate great-circle distance |
|---|---|
| New York to London | 5,570 km (3,461 miles) |
| Sydney to Tokyo | 7,826 km (4,863 miles) |
These are “as the crow flies” distances. Flights usually travel a little further because of air routes and winds, and road distances are typically much longer.
The calculator also gives the initial bearing: the compass direction you’d set off in from the first point. On a great-circle route, the bearing changes along the way, which is why flights from North America to Europe curve north on a flat map.
Most world maps stretch areas near the poles, so the shortest path between two cities looks like a curve bending towards the nearest pole. On a globe, that same path is a straight cut across the surface. A flight from New York to London heads north-east at first, with an initial bearing of about 51°, then gradually turns more easterly as it crosses the Atlantic. Pulling a piece of string tight between two cities on a globe is an easy way to see a great-circle route for yourself.
| Unit | Equals |
|---|---|
| 1 mile | 1.609344 km |
| 1 nautical mile | 1.852 km, used at sea and in aviation |
| 1 km | about 0.621 miles |
For 2D and 3D coordinates, the distance is in the same unit as the coordinates, whether that’s metres, feet, pixels or grid squares.
Most online map services show the coordinates of a place when you select it, usually in decimal degrees such as 51.5074, −0.1278. If you have degrees, minutes and seconds instead, convert them: decimal degrees = degrees + minutes ÷ 60 + seconds ÷ 3,600. For example, 40° 42′ 46″ N becomes 40 + 42 ÷ 60 + 46 ÷ 3,600 ≈ 40.7128. Remember to make south latitudes and west longitudes negative.
For related questions, use the slope calculator to find the slope and equation of a line, or the pythagorean theorem calculator to find the missing side of a right triangle.
d = √((x₂ − x₁)² + (y₂ − y₁)²). It finds the straight-line distance between two points on a plane.
The horizontal and vertical differences form the legs of a right triangle, and the distance is the hypotenuse, so d² = Δx² + Δy².
Add the squared change in z: d = √(Δx² + Δy² + Δz²). For changes of 3, 4 and 12, the distance is 13.
Use the haversine formula, which accounts for the Earth's curvature. Choose Latitude and longitude in the calculator and enter both points in decimal degrees.
No. It's the straight-line, great-circle distance. Road distances are usually longer.
No. Distance is always zero or positive because the differences are squared before adding.
5, because √(3² + 4²) = √25 = 5.
As negative numbers. New York's longitude is about −74.006.
The spherical model is typically within about 0.5% of precise ellipsoid calculations, which is ample for travel planning and estimates.
Exactly 1.852 km, originally based on one minute of latitude. It's used in shipping and aviation.
Euclidean distance is the straight-line length between two points. Manhattan distance adds the horizontal and vertical moves, as if travelling along a street grid.
Average the x-coordinates and the y-coordinates. The midpoint of (1, 2) and (4, 6) is (2.5, 4).