Euclidean distance is the ordinary straight-line distance between two points in Euclidean space. In geometry, it represents the length of the segment joining them; in numerical applications, it measures separation between coordinate vectors. Its coordinate formula extends the Pythagorean theorem to any finite number of dimensions. It is the distance induced by the Euclidean norm, also called the 2-norm, and is a standard example of a metric. (assets.cambridge.org)
Definition and coordinate formula
For points and in , with real-number coordinates, Euclidean distance is
This formula assumes orthonormal coordinate axes: the axes are mutually perpendicular and use the same unit of length. In one dimension, it reduces to . In two dimensions, the coordinate differences form the legs of a right triangle, whose hypotenuse joins the points. The same construction extends to three and higher dimensions. (assets.cambridge.org)
For example, the distance between and is
In linear algebra, the displacement belongs to a vector space, and the distance can be written
where is the standard inner product. The norm measures a vector’s length; distance measures the length of the difference between two points. (bpb-us-e1.wpmucdn.com)
Metric and geometric properties
Euclidean distance makes a metric space. It satisfies four defining properties: nonnegativity; zero distance exactly when the points coincide; symmetry, ; and the triangle inequality,
The last property expresses that traveling directly between two points is no longer than traveling through an intermediate point. Algebraically, it follows from the triangle inequality for the Euclidean norm. (assets.cambridge.org)
Distances are unchanged when both points undergo the same translation, rotation, or reflection. For an orthogonal matrix , whose transpose satisfies , and a translation vector ,
Thus, changing an orthonormal coordinate frame does not change the underlying distance. Multiplying all coordinates by a scalar , however, multiplies distances by . These statements follow from length preservation under orthogonal transformations and the homogeneity of the norm. (ocw.mit.edu)
Squared Euclidean distance
Squared Euclidean distance omits the square root:
It preserves distance rankings because squaring is strictly increasing for nonnegative numbers. Consequently, a nearest-point search can compare squared distances without computing square roots. Nevertheless, squared distance is not itself a metric: for points on a line, the squared distances give , violating the triangle inequality. This counterexample follows directly from the formula. (docs.scipy.org)
Squared distances are especially important in mathematical optimization. K-means clustering minimizes the sum of squared distances from observations to their assigned centers. Likewise, mean squared error is the squared Euclidean distance between prediction and target vectors divided by their number of components. Squaring changes how errors contribute to an objective, even though it leaves individual nearest-neighbor rankings unchanged. (scikit-learn.org)
Applications and feature scaling
In machine learning, observations are often represented as numerical feature vectors. The k-nearest neighbors algorithm can use Euclidean distance to identify nearby observations for classification or regression. Spatial search structures, including the KD-tree and ball tree, organize points to accelerate suitable neighbor queries. Their performance depends on dimensionality and the structure of the data. (scikit-learn.org)
The meaning of proximity depends on coordinate scales. A feature whose numerical range is much larger than others can dominate the sum of squared differences. Feature scaling therefore changes the geometry used by distance-based methods. Standardization subtracts each feature’s mean and divides by its standard deviation; the resulting distance expresses differences relative to feature variability rather than original units. Centering alone does not change pairwise distances, because the shared mean cancels in each difference. (scikit-learn.org)
High dimensionality also affects interpretation and computation. The curse of dimensionality can reduce the effectiveness of spatial search, and distance-based clustering can behave differently as dimensions increase. Dimensionality reduction changes the representation in which distances are evaluated; it does not automatically preserve every original distance. (scikit-learn.org)
Related distances and computation
Euclidean distance is the case of Minkowski distance. Weighted Euclidean distance replaces the squared differences with ; positive weights correspond to rescaling individual coordinates. Mahalanobis distance incorporates an inverse covariance matrix, allowing the measure to account for differing variability and correlations. (scikit-learn.org)
For unit-length vectors, expansion of the inner product gives
Their Euclidean-distance ranking therefore agrees with the reverse ranking of cosine similarity. Without normalization, Euclidean distance also depends on vector magnitudes. (docs.scipy.org)
Computational implementations may use
This identity supports efficient pairwise calculations and reuse of precomputed norms. However, subtracting nearly equal large terms can cause numerical cancellation, so algebraically equivalent formulas need not produce identical floating-point results. (scikit-learn.org)