Euclidean Distance Formula — 2D, 3D & nD

Euclidean Distance Formula — 2D, 3D & nD

TL;DR

The euclidean distance formula measures the straight-line distance between two points: in 2D it is d=(x2−x1)²+(y2−y1)², a direct consequence of the Pythagorean theorem. This article derives it from a right triangle, extends it to 3D and any number of dimensions, works through examples, and flags the mistakes that cost marks.

What Is the Euclidean Distance Formula?

The euclidean distance formula gives the length of the straight line segment between two points — the shortest path between them in flat (Euclidean) space. For two points (x1,y1) and (x2,y2) in a plane:

d=(x2−x1)²+(y2−y1)²

It answers a single question: how far apart are these two points, measured in a straight line? Because it is built from squares, the result is always zero or positive — distance is never negative.

How Do You Derive the Euclidean Distance Formula?

The formula is the Pythagorean theorem wearing coordinates. Drop a horizontal and a vertical line from the two points and you build a right triangle.

Pythagoras says the hypotenuse squared equals the sum of the squares of the legs:

d²=(x2−x1)²+(y2−y1)²

Take the positive square root:

d=(x2−x1)²+(y2−y1)²

Squaring each leg also removes any sign issue — it does not matter which point you call "first." That is the entire derivation, and it is why some texts call this the Pythagorean distance.

The Formula in 3D and n Dimensions

The same triangle logic adds one term per dimension. In 3D, with points (x1,y1,z1) and (x2,y2,z2):

d=(x2−x1)²+(y2−y1)²+(z2−z1)²

The pattern never changes — square each coordinate difference, add them, take the root. For two points a=(a1,a2,…,an) and b=(b1,b2,…,bn) in n-dimensional space:

d=∑i=1n(bi−ai)²

This is exactly what lets a recommendation engine measure "distance" between users described by hundreds of features — the same triangle, just in more dimensions than we can draw.

Examples of Euclidean Distance Formula

Example 1

Find the distance between (0,0) and (3,4).

d=(3−0)²+(4−0)²=9+16=25=5

Final answer: 5 — the classic 3-4-5 right triangle.

Example 2

Find the distance between (−2,5) and (4,−3).

Wrong attempt. A frequent first move is to subtract before squaring and skip the parentheses: 4−(−2)=6 and −3−5=−8, then writing d=6²−8²=36−64=−28. A negative under the root is impossible for a real distance — the slip was subtracting the squared terms instead of adding them.

Correct. The formula always adds the squared differences:

d= (4−(−2))²+(−3−5)²=6²+(−8)²=36+64=100=10

Final answer: 10. Squaring makes both terms positive, so the sum under the root can never be negative.

Example 3

Find the distance between (1,2) and (4,6).

d=(4−1)²+(6−2)²=9+16=25=5

Final answer: 5.

Example 4

Find the distance between the 3D points (1,2,3) and (4,6,15).

d=(4−1)²+(6−2)²+(15−3)²=9+16+144=169=13

Final answer: 13.

Example 5

Two points are (a,b) and (−a,−b). Find the distance between them.

d=(−a−a)²+(−b−b)²=(−2a)²+(−2b)²=4a²+4b²=2√(a²+b²)

Final answer: 2√(a²+b²). The formula works just as cleanly with variables as with numbers.

Example 6

A drone at (2,3,10) must reach a target at (5,7,22). How far is the straight-line flight?

d=(5−2)²+(7−3)²+(22−10)²=9+16+144=169=13

Final answer: 13 units — the direct path, ignoring obstacles.

Why the Euclidean Distance Formula Matters

The idea of "shortest straight-line distance" sounds obvious, but writing it as an equation is what makes it computable — and once it is computable, machines can use it.

What Are the Most Common Mistakes With the Euclidean Distance Formula?

Mistake 1: Subtracting the squared terms instead of adding

Where it slips in: Points with negative coordinates, where signs get tangled.

Don't do this: Write d=(x2−x1)²−(y2−y1)².

The correct way: The squared differences are always added: d=(x2−x1)²+(y2−y1)².

Mistake 2: Forgetting the square root

Where it slips in: Rushing through and reporting d² as the answer.

Don't do this: Stop at (x2−x1)²+(y2−y1)² and call it the distance.

The correct way: That sum is d², not d. The final step is the square root. The rusher who skips it reports 25 instead of 5 and loses the mark on the last line.

Mistake 3: Mismatching the coordinate pairing

Where it slips in: Mixing up which x goes with which y across the two points.

Don't do this: Pair x2 with y1, or subtract x from y.

The correct way: Subtract x from x and y from y — keep each axis with itself.

The Mathematicians Behind the Euclidean Distance Formula

Euclid of Alexandria (c. 300 BCE, Greece) laid out the geometry of flat space in his Elements, the framework that gives "Euclidean" distance its name and its straight-line meaning.

Pythagoras of Samos (c. 570–495 BCE, Greece) is credited with the right-triangle relation a²+b²=c² that the distance formula is built directly upon.

Conclusion

Practice These Before Moving On

Work through these, then check by sketching the right triangle.

  1. Find the distance between (2,1) and (5,5).
  2. Find the distance between the 3D points (0,0,0) and (2,3,6).
  3. Verify whether (0,0), (4,0), and (2,2√3) form an equilateral triangle using the distance formula.