Distance Calculator: 2D & 3D Distance, Midpoint
The distance between two points is the length of the straight line joining them — the shortest path from one to the other. It comes straight from Pythagoras' theorem: in two dimensions the distance is the hypotenuse of a right triangle whose sides are the horizontal and vertical gaps between the points.
Enter the coordinates of two points — in 2D (x, y) or 3D (x, y, z) — and this calculator gives the distance between them, the midpoint, and the step-by-step working. It works with decimals and negative coordinates.
Distance between the points (2D)
How It Works
The distance formula is Pythagoras' theorem rearranged. If the two points are (x1, y1) and (x2, y2), the horizontal gap is (x2 − x1) and the vertical gap is (y2 − y1), and the distance is the hypotenuse:
d = √((x2 − x1)² + (y2 − y1)²)
In three dimensions the same idea extends with a third term for the z-coordinates: d = √((x2 − x1)² + (y2 − y1)² + (z2 − z1)²). This straight-line measure is called the Euclidean distance, and it is the distance most people mean when they say "how far apart" — as the crow flies, not along roads or grid lines. (The grid-line version, where you can only move horizontally and vertically, is the Manhattan distance, and it is always at least as large.)
The midpoint is the point exactly halfway between the two: average each coordinate separately. In 2D that is ((x1 + x2) ÷ 2, (y1 + y2) ÷ 2), and in 3D the z-coordinate is averaged the same way. The midpoint is the same distance from both points — half the total distance — which makes it useful for finding centres, balancing loads and splitting a line segment evenly.
Because the differences are squared before they are added, the order of the points does not matter: the distance from A to B is the same as from B to A, and a negative gap contributes exactly as much as a positive one. The result is always zero or positive, and it is measured in whatever units your coordinates use — metres, pixels, miles or plain units. When distance becomes a journey, speed joins in — and to convert mph to kph, multiply by 1.60934.
Worked Example
Take the points (1, 2) and (4, 6). The differences are Δx = 4 − 1 = 3 and Δy = 6 − 2 = 4, so the distance is √(3² + 4²) = √(9 + 16) = √25 = 5 — the familiar 3-4-5 right triangle. The midpoint is ((1 + 4) ÷ 2, (2 + 6) ÷ 2) = (2.5, 4).
In 3D, take (1, 2, 3) and (4, 6, 3). The differences are Δx = 3, Δy = 4 and Δz = 3 − 3 = 0, so the distance is √(9 + 16 + 0) = √25 = 5 again — the z-coordinates are equal, so they add nothing. The midpoint is (2.5, 4, 3).
And if both points are the same, say (3, 4) and (3, 4), every difference is 0 and the distance is 0. That is a valid answer, not an error — the midpoint is the point itself, (3, 4).
Assumptions
- Straight-line (Euclidean) distance. The result is the shortest path between the points. It is not a road distance, a grid distance, or a distance on the surface of the Earth.
- Same units throughout. Both points must be measured in the same units — the answer comes out in those units, whatever they are.
- Plain coordinates, not latitude and longitude. For points on a map given as latitude and longitude, the curvature of the Earth matters and this formula underestimates the distance; a haversine calculation is the right tool for that.
- Results rounded to 4 decimal places. Distances like √2 (1.41421356…) are shown as 1.4142; the underlying calculation uses full precision.
- Coordinate cap. Each coordinate must be 1,000,000,000 or less in size, which keeps every result well inside the range JavaScript numbers handle exactly.
Sources: No external data is used on this page — every figure is calculated from the coordinates you enter, using the standard Euclidean distance formula and midpoint formula. Last reviewed: 15 November 2026.
Built and tested by SumKitTool — see how we check our numbers.
How to Use This Calculator
Pick 2D or 3D, then enter the coordinates of the two points. The headline result is the distance, and the table shows the midpoint, the change in each coordinate, and the full working — the squared differences and the square root — so you can check every step. Results update as you type, and the Reset button restores the worked example (1, 2) to (4, 6).
To see the 3D mode in action, switch the dimensions to 3D: the defaults become (1, 2, 3) and (4, 6, 3), giving a distance of 5 and a midpoint of (2.5, 4, 3). Change the z-values apart from each other — for example z1 = 3 and z2 = 7 — and watch the distance grow as the third dimension contributes.
Tips and Practical Advice
Use the 3-4-5 triangle as a sanity check: any two points 3 apart in one direction and 4 in the other are exactly 5 apart. If your points are 6 and 8 apart, the distance is 10 — the pattern scales. Spotting these Pythagorean triples is a quick way to catch a typo in your coordinates.
Negative coordinates are no problem. The distance between (−3, −4) and (0, 0) is 5, the same as between (3, 4) and (0, 0) — squaring removes the sign. What matters is the gap between the points, not where they sit on the grid.
The midpoint is the average of the coordinates, so it is always between the two points on every axis. If the midpoint looks wrong — outside the range of your inputs, for instance — one of the coordinates was probably mistyped.
Frequently Asked Questions
How do you find the distance between two points?
Subtract the coordinates, square the differences, add them and take the square root: d = √((x₂ − x₁)² + (y₂ − y₁)²). For (1, 2) and (4, 6) the differences are 3 and 4, so d = √(9 + 16) = √25 = 5. In 3D, add (z₂ − z₁)² inside the square root.
What is the midpoint formula?
The midpoint is the point halfway between two points: average each pair of coordinates. For (1, 2) and (4, 6) that gives (2.5, 4) — the centre of the segment whose length this calculator measures. The Midpoint Calculator covers midpoints in 2D and 3D in full.
What is the distance between two identical points?
Zero. If both points have the same coordinates, every difference is 0 and the distance is 0 — and the midpoint is the point itself. That is a valid answer, not an error, and this calculator shows it as 0.
Can the distance between two points be negative?
No. Distance is the length of a line, and lengths are never negative. The differences between coordinates can be negative — going from x = 6 to x = 1 gives −5 — but squaring removes the sign, so the distance is always zero or positive.
Last updated: