Euclidean Distance Formula — 2D, 3D & nD

#Math Formula
TL;DR
The euclidean distance formula measures the straight-line distance between two points: in 2D it is $d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$, 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.
BT
Bhanzu TeamLast updated on June 22, 20266 min read

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 $(x_1, y_1)$ and $(x_2, y_2)$ in a plane:

$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$

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.

  • The horizontal leg runs from $x_1$ to $x_2$, so its length is $x_2 - x_1$.

  • The vertical leg runs from $y_1$ to $y_2$, so its length is $y_2 - y_1$.

  • The straight-line distance $d$ is the hypotenuse.

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

$$d^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2$$

Take the positive square root:

$$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$$

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 $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$:

$$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}$$

The pattern never changes — square each coordinate difference, add them, take the root. For two points $\mathbf{a} = (a_1, a_2, \dots, a_n)$ and $\mathbf{b} = (b_1, b_2, \dots, b_n)$ in $n$-dimensional space:

$$d = \sqrt{\sum_{i=1}^{n} (b_i - a_i)^2}$$

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 = \sqrt{(3 - 0)^2 + (4 - 0)^2} = \sqrt{9 + 16} = \sqrt{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 = \sqrt{6^2 - 8^2} = \sqrt{36 - 64} = \sqrt{-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 = \sqrt{(4 - (-2))^2 + (-3 - 5)^2} = \sqrt{6^2 + (-8)^2} = \sqrt{36 + 64} = \sqrt{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 = \sqrt{(4 - 1)^2 + (6 - 2)^2} = \sqrt{9 + 16} = \sqrt{25} = 5$$

Final answer: $5$.

Example 4

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

$$d = \sqrt{(4 - 1)^2 + (6 - 2)^2 + (15 - 3)^2} = \sqrt{9 + 16 + 144} = \sqrt{169} = 13$$

Final answer: $13$.

Example 5

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

$$d = \sqrt{(-a - a)^2 + (-b - b)^2} = \sqrt{(-2a)^2 + (-2b)^2} = \sqrt{4a^2 + 4b^2} = 2\sqrt{a^2 + b^2}$$

Final answer: $2\sqrt{a^2 + b^2}$. 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 = \sqrt{(5 - 2)^2 + (7 - 3)^2 + (22 - 10)^2} = \sqrt{9 + 16 + 144} = \sqrt{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.

  • Machine learning and clustering. Algorithms like k-means group data points by euclidean distance; "similar" literally means "close in this space."

  • Computer vision and navigation. Face matching, object tracking, and GPS-style nearest-point queries all reduce to distance comparisons. A map app finding the nearest hospital is ranking euclidean distances.

  • Geometry and proofs. It verifies whether three points form an equilateral triangle, whether points are collinear, or which side of a polygon is longest.

  • A known limitation. Euclidean distance is straight-line distance. On a city grid where you can only travel along streets, the Manhattan distance (sum of the absolute coordinate differences) is the honest measure — euclidean would undercount the actual walk.

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 = \sqrt{(x_2 - x_1)^2 - (y_2 - y_1)^2}$.

The correct way: The squared differences are always added: $d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$.

Mistake 2: Forgetting the square root

Where it slips in: Rushing through and reporting $d^2$ as the answer.

Don't do this: Stop at $(x_2 - x_1)^2 + (y_2 - y_1)^2$ and call it the distance.

The correct way: That sum is $d^2$, 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 $x_2$ with $y_1$, 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^2 + b^2 = c^2$ that the distance formula is built directly upon.

Conclusion

  • The euclidean distance formula is $d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$ — the straight-line distance between two points.

  • It is the Pythagorean theorem in coordinates; the legs are the coordinate differences and the distance is the hypotenuse.

  • Extend it to any dimension by adding one squared difference per axis under the root.

  • The top mistakes are subtracting instead of adding the squared terms, and forgetting the final square root.

  • Euclidean measures straight-line distance; Manhattan distance is the right tool on a grid.

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\sqrt{3})$ form an equilateral triangle using the distance formula.

Want a live Bhanzu trainer to walk your child through more euclidean distance formula problems? Book a free demo class — online globally.

Was this article helpful?

Your feedback helps us write better content

Frequently Asked Questions

What is the euclidean distance formula?
It is the straight-line distance between two points: $d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$ in 2D, extended by one squared term per added dimension.
Does the Pythagorean theorem help find euclidean distance?
Yes — the formula is the Pythagorean theorem applied to the horizontal and vertical gaps between the points.
Can you find euclidean distance in 3D?
Yes. Add the squared difference in $z$: $d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}$.
What is the difference between euclidean and Manhattan distance?
Euclidean is the straight-line ("as the crow flies") distance using squares and a root. Manhattan distance sums the absolute coordinate differences, modelling travel along a grid of streets.
Can euclidean distance be negative?
No. Every term is squared, so the value under the root is never negative, and distance is always zero or positive.
✍️ Written By
BT
Bhanzu Team
Content Creator and Editor
Bhanzu’s editorial team, known as Team Bhanzu, is made up of experienced educators, curriculum experts, content strategists, and fact-checkers dedicated to making math simple and engaging for learners worldwide. Every article and resource is carefully researched, thoughtfully structured, and rigorously reviewed to ensure accuracy, clarity, and real-world relevance. We understand that building strong math foundations can raise questions for students and parents alike. That’s why Team Bhanzu focuses on delivering practical insights, concept-driven explanations, and trustworthy guidance-empowering learners to develop confidence, speed, and a lifelong love for mathematics.
Related Articles
Book a FREE Demo ClassBook Now →