terican

Last verified · v1.0

Calculator · math

Euclidean Distance Calculator

Compute straight-line distance between two points in 2D, 3D, or 4D space using the Euclidean distance formula d = √∑(qᵢ − pᵢ)².

FreeInstantNo signupOpen source

Inputs

Euclidean Distance

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Euclidean Distanceunits

The formula

How the
result is
computed.

What Is Euclidean Distance?

Euclidean distance is the straight-line distance between two points in any number of dimensions. Named after the ancient Greek mathematician Euclid, it represents the shortest path connecting two locations through space — the as-the-crow-flies measurement most people intuitively picture when they think of distance. This metric forms the backbone of analytic geometry and powers algorithms across data science, computer graphics, robotics, and physics.

The Euclidean Distance Formula

The general formula for n-dimensional Euclidean distance between points P(p₁, p₂, …, pₙ) and Q(q₁, q₂, …, qₙ) is:

d = √∑(qᵢ − pᵢ)²   for i = 1 to n

The formula squares each coordinate difference to eliminate negative values, sums those squared differences, then extracts the square root to yield the actual distance. According to Stanford's n-Dimensional Euclidean Distance reference, this generalization holds consistently across 2D, 3D, and arbitrarily higher-dimensional spaces without modification to its logic.

2D Distance Formula

For two points P(x₁, y₁) and Q(x₂, y₂) in a flat plane:

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

This is a direct application of the Pythagorean theorem. The horizontal separation (x₂ − x₁) and vertical separation (y₂ − y₁) form the two legs of a right triangle, and the distance is the hypotenuse. As Khan Academy's analytic geometry series demonstrates, this geometric derivation makes the formula intuitive rather than merely memorized.

3D Distance Formula

Adding a z-axis extends the formula to three-dimensional space. For P(x₁, y₁, z₁) and Q(x₂, y₂, z₂):

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

4D Distance Formula

In four-dimensional space — relevant to physics (spacetime) and machine learning (feature spaces) — a fourth coordinate w is added:

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

Worked Example: 2D

Find the distance between A(3, 4) and B(7, 1):

  • x-difference: 7 − 3 = 4; squared: 16
  • y-difference: 1 − 4 = −3; squared: 9
  • Sum of squares: 16 + 9 = 25
  • Square root: √25 = 5 units

Worked Example: 3D

Find the distance between P(1, 2, 3) and Q(5, 5, 3):

  • Differences: (5−1) = 4, (5−2) = 3, (3−3) = 0
  • Squares: 16 + 9 + 0 = 25
  • Result: √25 = 5 units

Real-World Applications

  • Navigation and GPS: Mapping tools compute straight-line distances between geographic coordinates for route estimation and proximity searches.
  • Machine learning: K-nearest neighbors (KNN) and K-means clustering rank and group data points by their Euclidean distance in feature space.
  • Computer graphics and game engines: Collision detection, lighting attenuation, and object-proximity checks rely on 3D Euclidean distance between vertices and camera positions.
  • Robotics and autonomous vehicles: Path-planning algorithms minimize cumulative Euclidean distance across waypoints to find efficient trajectories.
  • Bioinformatics: Researchers measure similarity between gene expression profiles as Euclidean distance in high-dimensional feature space.

Important Considerations

Euclidean distance assumes all dimensions share the same scale and unit. When variables differ in magnitude — such as mixing age in years with income in dollars — dimensions with larger values dominate the result. Normalizing features before computation or switching to Mahalanobis distance corrects this imbalance. As detailed in Euclidean Distance Geometry and Applications (UC Davis), high-dimensional spaces also exhibit the curse of dimensionality, where pairwise distances converge and lose discriminatory power above roughly 10 to 20 dimensions.

Reference

Frequently asked questions

What is Euclidean distance and when should it be used?
Euclidean distance is the straight-line distance between two points, calculated as the square root of the sum of squared coordinate differences. Use it when all dimensions share the same unit of measurement and scale, such as comparing spatial coordinates (x, y, z) or normalized feature vectors in machine learning. It is the default distance metric in geometry, physics simulations, and algorithms including K-means clustering and K-nearest neighbors classification.
How does the Euclidean distance formula relate to the Pythagorean theorem?
In two dimensions, the Euclidean distance formula is a direct restatement of the Pythagorean theorem: a² + b² = c². The horizontal difference (x₂ − x₁) and vertical difference (y₂ − y₁) form the two legs of a right triangle, and the distance between the points is the hypotenuse c. The 3D and 4D formulas extend this reasoning by adding one squared-difference term for each additional dimension, always taking the square root of the total sum.
What is the difference between Euclidean distance and Manhattan distance?
Euclidean distance measures the straight-line path between two points, while Manhattan distance sums the absolute differences along each axis separately — like navigating a city street grid where only horizontal and vertical movement is possible. Between points (0, 0) and (3, 4): Euclidean distance equals 5, but Manhattan distance equals 7. Manhattan distance is preferred when movement is restricted to grid-like paths, or when squaring large differences would over-penalize outlier coordinates in the data.
How do you calculate Euclidean distance in 3D space?
Apply the formula d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²). For example, between P(2, 3, 1) and Q(5, 7, 1): the differences are 3, 4, and 0; the squares are 9, 16, and 0; the sum is 25; and the distance is √25 = 5 units. This three-dimensional version is essential in physics simulations, 3D game engines, and engineering contexts where spatial relationships involve height, depth, and width simultaneously.
Can Euclidean distance be used in machine learning?
Yes. Euclidean distance is the core similarity metric in several foundational machine learning algorithms. K-nearest neighbors (KNN) classifies new observations by finding the K training examples with the smallest Euclidean distance. K-means clustering assigns each data point to the nearest centroid based on Euclidean distance and iterates until convergence. Always normalize or standardize features before computing distances in machine learning — otherwise variables with large numeric ranges will dominate and bias the results significantly.
What are the limitations of Euclidean distance in high-dimensional data?
In high-dimensional spaces — typically above 10 to 20 dimensions — all pairwise Euclidean distances tend to converge toward the same value, making it difficult to distinguish near neighbors from distant ones. This phenomenon is known as the curse of dimensionality. Euclidean distance is also sensitive to differences in scale across dimensions and to extreme outlier values. Alternatives such as cosine similarity, Mahalanobis distance, or dimensionality reduction via PCA often outperform raw Euclidean distance on high-dimensional datasets.