Data Science & ML
Basic

Euclidean Distance

Straight-line distance between two points in n-dimensional space.

Formula

d=∑i=1n(ai−bi)2d = \sqrt{\sum_{i=1}^{n}(a_i - b_i)^2}

Variables

a_i,b_iCoordinates
nDimensions

Example

Between (0,0) and (3,4): d = 5

How it works

Euclidean distance measures how far apart two points are by treating each coordinate difference as a leg of a right triangle (or its higher-dimensional equivalent) and combining them with the Pythagorean theorem. Squaring the coordinate gaps removes negative signs and makes larger differences count more strongly, then taking the square root brings the result back to the original unit. In data science, it gives a natural notion of “nearest” when all dimensions are on the same scale and every feature is equally important.

When to use it

Use this when you need to compare similarity between numeric data points, such as in clustering, nearest-neighbor search, or checking how close two vectors are. It is most appropriate when the features are continuous and measured on comparable scales.

Worked example, step by step

Find the distance between A = (2, 1, 5) and B = (6, 4, 1). Step 1: Subtract coordinates: (2 - 6) = -4, (1 - 4) = -3, (5 - 1) = 4 Step 2: Square each difference: (-4)^2 = 16, (-3)^2 = 9, 4^2 = 16 Step 3: Add the squares: 16 + 9 + 16 = 41 Step 4: Take the square root: d = sqrt(41) Final answer: d ≈ 6.40

Common mistakes to avoid

  • Forgetting to square the coordinate differences before adding them
  • Mixing up coordinate order and subtracting the wrong points
  • Using Euclidean distance on features with very different scales without normalizing them first

Did You Know?

The basis of k-nearest-neighbors and k-means clustering.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026