Euclidean Distance Calculator
Euclidean distance is the straight-line distance between two points: the length of the segment joining them, with nothing in between. This calculator works the formula in the open. Choose 2D or 3D, enter the coordinates, and it returns the distance with the full substitution, the midpoint, the squared distance, the slope in 2D, and the exact simplified radical form when the answer is a surd, so a homework answer like 4√2 matches instead of hiding inside a decimal.
One boundary, stated up front: this page is for flat Cartesian coordinates only. It does not convert units and it does not handle latitude and longitude, because degrees on a sphere are not flat x and y values. For GPS coordinates, great-circle distance, and bearings, use the broader distance calculator, which covers points and places on Earth in one tool. This page stays with the formula itself, and goes deeper on it than a general tool can.
Distance, midpoint, squared distance, slope and exact radical form for two points in 2D or 3D.
Quick Answer
Quick Answer: the distance between two points is d = √((x2 − x1)² + (y2 − y1)²), with a third squared term added in 3D. The calculator is pre-filled with (1, 2) and (4, 6): the differences are 3 and 4, the squares sum to 25, and the distance is exactly 5, with midpoint (2.5, 4) and slope 1.333333. Switch to 3D and the pre-filled z values give √50 = 7.071068, exact form 5√2. One click on Calculate reproduces both.
- Quick Answer
- The formula: Pythagoras, extended one axis at a time
- Worked examples, checked against the tool
- The three extra outputs, and when each one earns its place
- Euclidean distance vs the other distances
- Where Euclidean distance does real work
- What other Euclidean distance calculators miss
- Frequently Asked Questions
- Add This Calculator to Your Website
- References
The formula: Pythagoras, extended one axis at a time
In 2D, the horizontal gap (x2 − x1) and the vertical gap (y2 − y1) are the two legs of a right triangle, and the distance is its hypotenuse. That is the whole derivation: the distance formula is the Pythagorean theorem wearing coordinates. In 3D the same trick runs twice, once across the floor of an imaginary box and once up its diagonal, which adds the (z2 − z1)² term under the same root.
The pattern does not stop at three axes. For points with n coordinates, the formula is d = √(Σ (pi − qi)²): subtract matching coordinates, square each difference, add, and take the root. That general version is the one statistics and machine learning actually use, where a "point" might be a customer described by forty numbers. This calculator accepts two or three coordinates per point, because those are the cases you can draw; the n-dimensional formula above is the same rule with more terms, worked by code rather than by hand.
Three properties follow directly from the formula and are worth knowing before you trust a result. The distance is never negative, because it is a square root of a sum of squares. It is zero only when the two points are identical. And it is symmetric: swapping the points flips the sign of every difference, and squaring erases the signs, so A to B always equals B to A.
Key takeaways
- The distance formula is the Pythagorean theorem: square each coordinate difference, add, take the root.
- This tool also returns the midpoint, the squared distance, the 2D slope, and the exact simplified radical (for example 4√2) when the sum of squares is a whole number.
- Flat coordinates only. Latitude and longitude need the haversine formula, not this one.
- Order never matters: A to B equals B to A, and distance is zero only for identical points.
Worked examples, checked against the tool
Both examples are pre-filled, one per mode, and every figure below is what the calculator returns for them.
| Step | 2D: (1, 2) to (4, 6) | 3D: (1, 2, 3) to (4, 6, 8) |
|---|---|---|
| Differences | dx = 3, dy = 4 | dx = 3, dy = 4, dz = 5 |
| Squared sum | 9 + 16 = 25 | 9 + 16 + 25 = 50 |
| Distance | 5 | 7.071068 |
| Exact form | 5 | 5√2 |
| Midpoint | (2.5, 4) | (2.5, 4, 5.5) |
| Slope | 1.333333 | Not shown in 3D |
A less tidy pair shows why the exact form matters. From (1, 2) to (5, 6) the differences are 4 and 4, the squared sum is 32, and the decimal answer is 5.656854. A textbook, though, gives the answer as 4√2, and students marking their own work can waste minutes deciding whether the two agree. This calculator prints both, so the match is instant. When the squared sum is not a whole number, no exact form exists to print and the tool simply omits it.
The three extra outputs, and when each one earns its place
Squared distance is the sum under the radical, before the root. It looks like a half-finished answer, but it is the quantity comparison code actually uses: if you only need to know which of two points is nearer, comparing squared distances gives the same winner without computing a single square root, which is why nearest-neighbor search and k-means clustering work with squared Euclidean distance internally. The ordering is identical because the square root never reverses an order.
Exact form simplifies the radical by pulling out square factors: √50 becomes 5√2, √32 becomes 4√2, √25 becomes plain 5. It appears only when the squared sum is a whole number, which covers most textbook and exam problems, since those are designed to simplify.
Slope (2D only) is dy/dx, the rise over run of the line through the two points. The tool reports it as a decimal, and says so honestly: if you need slope as an exact fraction, or a Manhattan grid distance alongside, the distance calculator reports both. A vertical pair, where dx is 0, gets the words "undefined (vertical line)" instead of a fake number, because division by zero has no answer.
The midpoint needs no selling: it averages each coordinate, sits exactly halfway along the segment, and is d/2 from each endpoint. It is also the first step toward a bigger idea: average many points and you get a centroid, the seed of clustering algorithms.
Euclidean distance vs the other distances
Euclidean is the default meaning of distance, but it is not the only one, and picking the wrong one is a real error rather than a style choice.
| Measure | Rule | (1, 2) to (4, 6) | Use it when |
|---|---|---|---|
| Euclidean | √(dx² + dy²) | 5 | Straight-line separation on a flat plane or in space |
| Manhattan | |dx| + |dy| | 7 | Movement is restricted to a grid, like city blocks |
| Chebyshev | max(|dx|, |dy|) | 4 | Diagonal moves cost the same as straight ones, like a chess king |
| Great-circle | Haversine formula | Not applicable | The coordinates are latitude and longitude on Earth |
Nearby questions have their own tools on this site. Three points and the three sides of their triangle belong to the distance between 3 points calculator. The shortest gap from a point to a line is the distance from a point to a line calculator, and the same question against a plane in 3D is the distance from a point to a plane calculator. Each is a different formula, not a mode of this one.
Where Euclidean distance does real work
Machine learning and data science. k-nearest neighbors classifies a new point by the Euclidean distance to its neighbors; k-means clustering assigns every point to the nearest centroid and then recomputes those centroids as coordinate averages, the midpoint idea scaled up. Feature scaling matters here: a coordinate measured in thousands will dominate one measured in decimals, which is why practitioners standardize features before trusting the distances.
Graphics, games, and robotics. Collision checks, camera distances, and pathfinding heuristics all start from the 3D form of this formula. Engines often compare squared distances for speed and take the root only for the winning candidate, the same shortcut this page exposes as an output.
Everyday geometry. Screen sizes are diagonal distances, ladder-and-wall problems are 2D distances in disguise, and a floor plan's corner-to-corner measurement decides whether a sofa fits through a room. If the numbers came off a graph, a drawing, or a tape measure on flat ground, this is the right formula. If they came off a GPS, they are not flat, and the haversine route above is the honest one.
What other Euclidean distance calculators miss
Six leading pages for this exact search were read before this rewrite. AJDesigner gives the distance and midpoint with a clean explanation, but no squared distance and no exact radical form. StatGarden and 1dollars.org both cover 2D and 3D with the per-axis gaps shown, and both stop at the decimal answer. Calculators.im adds Manhattan distance and a latitude/longitude mode, which makes it a general distance hub rather than a formula page, and it still shows no surd form. Calculoonline describes an n-dimensional input in its how-to text that its own coordinate fields do not deliver, a claim worth checking on any page, including this one. None of the six simplifies the radical, and none reports the squared distance that comparison algorithms actually use. This page does both, shows the full substitution for your own numbers, and states its flat-coordinates boundary instead of implying it can handle GPS points.
Frequently Asked Questions
Euclidean distance is the straight-line distance between two points, computed from the Pythagorean theorem: square each coordinate difference, add the squares, and take the square root. It is the default meaning of distance in geometry, graphics, and most of machine learning.
In 2D, d = √((x2 − x1)² + (y2 − y1)²). In 3D, add a third term: d = √((x2 − x1)² + (y2 − y1)² + (z2 − z1)²). For n dimensions, keep adding one squared difference per coordinate under the same root.
No. The formula takes the square root of a sum of squares, which is always zero or positive. Distance is 0 only when the two points are identical.
When the squared distance is a whole number, the tool simplifies the radical: √50 is shown as 5√2 and √32 as 4√2, alongside the decimal. That is the form textbooks and exam answers use. When the squared sum is not a whole number, no exact form is shown.
Because comparisons often need it directly. Nearest-neighbor and clustering code compares squared distances to skip the square root: the nearest point by squared distance is the nearest point by distance, so the shortcut never changes the answer.
No. Latitude and longitude are angles on a sphere, not flat coordinates, and feeding them into this formula gives a wrong answer that gets worse away from the equator. Use the distance calculator linked above, which applies the haversine formula to GPS coordinates.
No. Swapping the points flips the sign of each difference, and squaring removes the signs, so the distance is identical either way. The slope in 2D is also unchanged, since both differences flip together.
Add This Calculator to Your Website
Embed this calculator on your own site with the code below. Pick a size to preview it live, then copy the code.
Powered by Calculator Zilo
References
- Weisstein, E. W. "Euclidean Distance." Wolfram MathWorld: the standard reference definition, with the n-dimensional form used in the formula section above.
- "Euclidean distance." Wikipedia: properties of the metric, its relation to the Pythagorean theorem, and the squared Euclidean distance used in statistics.
- Weisstein, E. W. "Point-Point Distance--2-Dimensional" and midpoint entries. Wolfram MathWorld distance collection: distance and midpoint formulas in two and three dimensions.
- "Distance formula." Khan Academy: a worked derivation of the 2D formula from the Pythagorean theorem, with practice examples.
