Distance Between Two Points: The Formula and When It Breaks

The Euclidean distance between two points is just the Pythagorean theorem stretched into more dimensions. This guide explains where the formula comes from, walks a worked 3-4-5 example, shows the 3D extension, lists the situations where Euclidean is the wrong tool (lat/long, taxi-cab grids, curved surfaces), and points out the small mistakes that most often produce a wrong answer.

#math#distance#coordinates#euclidean#geometry#pythagorean-theorem

What "distance between two points" actually means

When someone asks for the distance between two points, they almost always mean the straight-line distance — the length of the shortest path that connects them through empty space. In flat (Euclidean) geometry that path is unique and easy to compute, which is why the distance calculator on this site returns it from nothing more than six numbers: the x, y and z coordinates of each point. The math is the same whether the coordinates describe two cities on a flat map, two pixels on a screen, two atoms in a crystal, or two feature vectors in a recommender system. Distance is a geometric property of the points, not of the units they happen to be measured in.

The catch is that "straight-line" only means what you think it means in flat space. If your points live on a curved surface (the Earth) or in a space where motion is constrained to a grid (city streets, pixel art, chess rooks), Euclidean distance is the wrong tool. We come back to those cases further down. For most problems — coordinate geometry homework, 2D and 3D engineering layouts, computer graphics, vector spaces in machine learning — the Euclidean formula is exactly what you want, and the distance calculator wraps it up with the per-axis deltas exposed so you can see the working.

The Euclidean distance formula

In two dimensions, the distance between point A at (x₁, y₁) and point B at (x₂, y₂) is:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

In three dimensions it gains a z term:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

The pattern continues into any number of dimensions — keep adding squared differences inside the square root. Each (x₂ − x₁) is a signed difference, but squaring it removes the sign, which is why the order of the two points does not matter: the distance from A to B equals the distance from B to A. That symmetry is one of the defining properties of a metric in the mathematical sense, and the Euclidean formula satisfies it for free.

The formula is a direct application of the Pythagorean theorem. Picture the two points in a plane and draw a right triangle whose horizontal leg runs from x₁ to x₂ along the x-axis and whose vertical leg runs from y₁ to y₂ along the y-axis. The hypotenuse — the third side, joining the two points directly — has length √(a² + b²) where a and b are the lengths of the legs. Those leg lengths are |x₂ − x₁| and |y₂ − y₁|, and squaring them removes the absolute-value signs, so the formula collapses to the one above. Pythagoras was 2,500 years ahead of us on this one. If you want to drill into the underlying theorem, the Pythagorean theorem calculator walks through the side / hypotenuse relationship with any pair of known sides.

Worked example: the 3-4-5 triangle, then 3D

Start with the textbook case in 2D. Take point A at (0, 0) and point B at (3, 4). The deltas are Δx = 3 − 0 = 3 and Δy = 4 − 0 = 4. Square each: 9 and 16. Sum: 25. Square root: 5. So the distance is exactly 5 units. This is the famous 3-4-5 right triangle — a Pythagorean triple with integer side lengths — and the distance calculator uses it as the default example for that reason. Plug those numbers in and you get 5 out, every time. The check is simple enough to do in your head, which makes it a useful sanity check for any distance implementation: if your code returns 5 for these inputs, the algebra is wired up correctly.

Now extend to 3D. Take point A at (1, 2, 3) and point B at (4, 6, 8). The deltas are Δx = 3, Δy = 4, Δz = 5. Square each: 9, 16, 25. Sum: 50. Square root: √50 ≈ 7.0711. The 3D distance is about 7.071 units. Notice that the 2D distance in the xy-plane is still √(9 + 16) = 5 — adding the z-axis grows the total distance by about 2.07, the contribution of the 5-unit climb in z. The calculator returns both numbers: the full 3D distance and the 2D distance in the xy-plane separately, so you can see how much of the total is horizontal and how much is vertical.

Negative coordinates do not break anything. Take A at (−5, −2) and B at (3, 4). Δx = 3 − (−5) = 8 and Δy = 4 − (−2) = 6. Square: 64 + 36 = 100. Distance: 10. The negative signs cancel inside the squares, which is exactly the behaviour you want — a point at (−5, 0) is the same distance from the origin as a point at (5, 0).

2D versus 3D: when each one applies

Two-dimensional distance is right whenever the problem genuinely lives in a plane. Floor-plan layouts. Top-down maps where elevation is ignored or treated separately. Computer-graphics screen positions. Scatter plots and chart geometry. Most coordinate-geometry homework. In each case, you have only x and y, and the z term either does not exist or is held constant so it cancels out. The 2D formula is just the 3D formula with z₁ = z₂, which makes the (z₂ − z₁)² term zero and drops it out of the sum.

Three-dimensional distance is right whenever elevation, depth or a third coordinate axis matters: physical objects in real space, molecular geometry, robotics arm reach, drone flight paths, 3D rendering, voxel volumes. The distance calculator handles both cases with the same interface: leave both z values at 0 and the result is the 2D answer; set them to non-zero numbers and you get the 3D answer. There is no separate "switch to 2D mode" — the formula collapses naturally when the z difference is zero.

For straight-line distance between two points that have a defined slope, the slope calculator is the natural companion. Distance answers "how far apart"; slope answers "at what angle" — and the two together fully describe a line segment in 2D.

Where Euclidean distance is the wrong tool

Latitude and longitude

Lat/long coordinates look like x/y but they are not Cartesian — they are angles on a sphere. Two points one degree of longitude apart are about 111 km apart at the equator, about 79 km apart at 45° latitude, and zero kilometres apart at the poles, where the meridians meet. Treating lat/long as flat x/y produces errors that grow with both distance and latitude. For separations of a few kilometres at mid-latitudes the error might be a percent or two, which is sometimes acceptable. For anything longer, use the haversine formula, which assumes a spherical Earth and is accurate to roughly 0.5 % over any distance. For survey-grade accuracy the Vincenty formula uses an ellipsoidal Earth model and is good to a millimetre.

Taxicab / Manhattan distance

If motion is constrained to axis-aligned steps — taxis on a city grid, a chess rook, pixel-grid path planning — the relevant distance is the sum of the absolute axis differences: |x₂ − x₁| + |y₂ − y₁|. For the points (0, 0) and (3, 4) the Manhattan distance is 7, not 5, because a taxi cannot cut the hypotenuse. Manhattan distance is also useful in some machine- learning settings because it is more robust to outliers than Euclidean, especially in high-dimensional sparse data.

Curved or non-Euclidean spaces

On the surface of a sphere or any other curved manifold, the shortest path between two points is not a straight Euclidean line but a geodesic — a great circle on a sphere, a curved path in general. The distance is the length of that geodesic, not the chord through the interior of the sphere. General relativity does similar things to space-time. None of this is relevant to a floor-plan calculation, but it is the reason aircraft routes look curved on a 2D world map: the shortest path between two airports is a great circle, not the apparent straight line.

Common mistakes

Forgetting to square before summing. A few people try to compute |x₂ − x₁| + |y₂ − y₁| and call it Euclidean distance. That gives Manhattan distance, not Euclidean. The squares-then-square-root sequence is not optional — it is what makes the formula give the straight-line answer rather than the grid-walked answer.

Forgetting the square root. Some algorithms intentionally work with squared distance — k-means clustering, for example — because it preserves the ordering and saves a square root per comparison. That is a valid optimisation, but the squared value is not the distance. If you report √50 ≈ 7.07 as 50, your answer is off by a factor of seven.

Confusing signed displacement with distance. Δx and Δy are signed displacements along each axis. Distance is the magnitude of the combined displacement and is always non-negative. A point at (−3, 0) is three units from the origin, not minus three. The negative sign belongs to the x-component of the displacement vector, not to the distance.

Mixing units between axes. If x is in metres and y is in feet, the distance formula will still produce a number, but it will be meaningless. The formula assumes all axes use the same units. Convert first, then compute. If you need to compare the result to a number in different units afterwards, the distance converter handles the conversion cleanly.

Applying the formula to lat/long without thinking. Covered in the previous section, but worth repeating: lat/long are not Cartesian. Plug them into the Euclidean formula and the only situation where the answer is approximately right is when both points are within a few kilometres of each other near the equator.

How to use the result

The distance calculator returns four things: the total distance, the deltas along each axis, and the 2D distance in the xy-plane as a reference. Use the deltas to check the working — if Δx and Δy match what you expect from the coordinates, the rest follows mechanically. Use the 2D-plane distance to see how much of the total distance is horizontal versus the climb in z. For a calculation where the z axis represents elevation, this split is often the more useful number: a hike with horizontal distance 1 km and elevation gain 500 m has a straight-line distance of about 1.12 km but a horizontal distance of 1 km, and the horizontal distance is the one your map app reports.

The output is dimensionally identical to the inputs. Coordinates in metres give a distance in metres. Coordinates in pixels give a distance in pixels. Coordinates in arbitrary feature-vector units give a distance in those same units, which is the basis of how nearest-neighbour algorithms and clustering work. The calculator does no unit conversion — that is intentional. Keep the inputs consistent and the output is meaningful.

When to step beyond the basic formula

Most distance problems do not need anything more sophisticated than the Euclidean formula in two or three dimensions. The exceptions worth flagging are:

Geographic distance on Earth. Use haversine for general use, Vincenty for survey-grade accuracy. Many online tools and most spatial databases have these built in.

High-dimensional feature spaces. Euclidean distance still works mathematically, but the so-called curse of dimensionality means it loses discriminating power. Cosine similarity or Manhattan distance often perform better in recommender systems and text embeddings.

Constrained motion. If the moving object cannot travel through walls, water or terrain, the relevant distance is the shortest navigable path, not the Euclidean straight line. Pathfinding algorithms (A*, Dijkstra) compute these on a graph representation of the space.

Outside these cases, the Euclidean formula does the job. The distance calculator computes it instantly for any pair of 2D or 3D points. If you need to chain it with another geometric calculation — slope, triangle sides, hypotenuse — the related calculators below are set up for exactly that.

Frequently asked questions

Is the distance formula the same as the Pythagorean theorem? Effectively, yes. The 2D distance formula is the Pythagorean theorem applied to a right triangle whose legs are the coordinate differences. The 3D version applies Pythagoras twice — once in the xy-plane, then again in the plane containing that 2D distance and the z axis. The general n-dimensional version is an iterated Pythagoras with one term per axis.

Why does the calculator show a 2D distance separately? Because the horizontal component is often the number you actually want. In navigation, route planning, and hiking, the ground distance matters more than the slant distance. Showing both lets you read off whichever is relevant without doing the algebra a second time.

Does this work for points in higher dimensions than three? The formula does — the calculator interface stops at three dimensions because almost no real-world physical problem needs more, and machine-learning users almost always work in code rather than a calculator UI. If you need n-dimensional Euclidean distance for a vector of 50 features, you are better off computing it directly in NumPy or your statistics package.

What is the most common error in a distance calculation? Sign errors in the subtraction step, by a wide margin. People write (x₁ − x₂) when they meant (x₂ − x₁) and then forget that squaring will save them anyway. The formula is robust to that slip, but if you are doing the algebra by hand, expanding the squares and then summing is more error-prone than just letting the distance calculator do the arithmetic and reading off the deltas to sanity-check the coordinates.

Frequently asked questions

What is the formula for the distance between two points?

In two dimensions, the distance between (x₁, y₁) and (x₂, y₂) is √((x₂ − x₁)² + (y₂ − y₁)²). In three dimensions, you include the z-axis: √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). This is called the Euclidean distance formula and it is a direct application of the Pythagorean theorem: the squared distance equals the sum of the squared differences along each axis. The formula extends naturally to any number of dimensions — just keep adding squared differences inside the square root.

Does the order of the points matter?

No. Each axis difference is squared inside the formula, so the sign drops out: (x₂ − x₁)² is the same as (x₁ − x₂)². The distance from A to B is always equal to the distance from B to A. Symmetry is one of the defining properties of any metric — if a "distance" function returned different answers depending on direction, it would not be a distance in the mathematical sense at all.

How is this different from the Manhattan or taxicab distance?

Euclidean distance is straight-line distance — the shortest possible path between two points in flat space. Manhattan (or taxicab) distance is the sum of the absolute axis differences: |x₂ − x₁| + |y₂ − y₁|. It is the distance a taxi would drive on a grid of streets where you cannot cut diagonally. For points (0, 0) and (3, 4), the Euclidean distance is 5 but the Manhattan distance is 7. Manhattan distance is the right tool when motion is constrained to axis-aligned steps — chess rooks, city blocks, pixel grids.

Can I use the Euclidean distance formula for latitude and longitude?

Only for very short distances — say, a few kilometres. Latitude and longitude are angular coordinates on a sphere, not Cartesian coordinates on a plane. Two points one degree of longitude apart are about 111 km apart at the equator but only about 79 km apart at 45° latitude, and zero kilometres apart at the poles. Treating lat/long as flat x/y gives errors that grow with distance and with latitude. For distances longer than a few kilometres, use the haversine formula, which accounts for the curvature of the Earth, or the Vincenty formula for survey-grade accuracy.

What units does the result use?

Whatever units you put in. The distance formula is dimensionally homogeneous: the output has the same units as the input coordinates. Enter coordinates in metres and you get metres back. Enter coordinates in pixels and you get pixels. The calculator does no unit conversion — it computes pure geometric distance. If you need to convert the result to another unit afterwards, run it through the distance converter.

How does the distance formula relate to the Pythagorean theorem?

The 2D distance formula is exactly the Pythagorean theorem applied to a right triangle whose two legs are parallel to the x and y axes. The horizontal leg has length |x₂ − x₁|, the vertical leg has length |y₂ − y₁|, and the hypotenuse — the straight-line distance — is the square root of the sum of their squares. The 3D version extends this: think of it as applying Pythagoras twice. First in the xy-plane to get the 2D distance, then again using that 2D distance and the z-axis difference as the two legs of a new right triangle whose hypotenuse is the 3D distance.

Does the formula work in more than three dimensions?

Yes — and this is where Euclidean distance earns its keep in machine learning, statistics and physics. In n dimensions, the distance between two points is √Σ (xᵢ − yᵢ)² for i from 1 to n. Recommendation engines compute distances between user vectors with hundreds of components; k-means clustering uses Euclidean distance in whatever feature space you give it; quantum mechanics uses an inner-product structure that reduces to Euclidean distance for real-valued state vectors. The geometric intuition gets harder to picture past three dimensions, but the algebra works the same.

What is a negative distance?

There is no such thing as a negative distance under this formula — the square root function returns a non-negative value, and squaring the differences guarantees the quantity inside the root is non-negative. If you see a negative number labelled "distance" somewhere, it is almost certainly a signed displacement along a single axis (a vector component, not a distance) or a scoring convention from a particular algorithm (some clustering methods report negative similarities, which are not the same as negative distances). Pure geometric distance is always zero or positive.

Informational only. Not personalised financial, legal, or tax advice.