Mahalanobis Distance Calculator

Enter the point, mean, and covariance values to compute Mahalanobis distance.

How it is calculated

For a two-variable point x = (x1, x2), mean m = (m1, m2) and covariance matrix S = [[s11, s12], [s12, s22]], the tool computes D² = dᵀ S⁻¹ d with d = x − m, then D = √D². The 2×2 inverse is built from the determinant det = s11·s22 − s12²: S⁻¹ = (1/det) · [[s22, −s12], [−s12, s11]]. s11 and s22 are the variances of each variable, s12 is their covariance, all in the squared units of the data. Both D and D² are shown with four decimals. The covariance matrix must be positive definite: s11 and s22 above zero and a determinant above zero, that is s12² < s11·s22. Otherwise (including perfectly correlated variables) no result is shown. All seven fields are required.

Worked example

Point (5, 8), mean (3, 5), s11 = 4, s22 = 9, s12 = 3. The deviation is d = (2, 3). The determinant is 4·9 − 3² = 27, so S⁻¹ = (1/27)·[[9, −3], [−3, 4]]. Then dᵀS⁻¹d = (9·4 − 2·3·2·3 + 4·9)/27 = (36 − 36 + 36)/27 = 1.3333. This is D², and its square root gives a Mahalanobis distance of 1.1547.

Try this example →

Common mistakes

  • Entering standard deviations in s11 and s22. These fields take variances (standard deviation squared); a standard deviation of 2 means s11 = 4.
  • Entering the correlation coefficient (between −1 and 1) as s12. The covariance is the correlation multiplied by both standard deviations.
  • Using an impossible covariance matrix. It needs s12² < s11·s22; with s11 = 4 and s22 = 9, any s12 of 6 or more in size (determinant zero or negative) gives no result.
  • Dropping the sign of the covariance. With the same point and mean, s12 = 3 gives D = 1.1547 but s12 = −3 gives D = 2.0000, because the direction of the correlation changes which points count as typical.
  • Reading D as D². The tool shows both, and a chi-square cut-off for two variables applies to D², not D.

About this calculator

The Mahalanobis distance measures how far a point is from a distribution's mean, but unlike ordinary Euclidean distance it accounts for the correlation and spread between variables by dividing through the distribution's covariance matrix: D² = (x − μ)ᵀ Σ⁻¹ (x − μ). A point that's far along a direction where the data varies a lot is treated as less unusual than the same distance along a direction where the data barely varies.

This makes it a standard tool in multivariate outlier and anomaly detection, cluster analysis, quality control, and classification — for example flagging fraudulent transactions, detecting faulty sensor readings, or measuring how typical a new observation is relative to a training dataset in machine learning pipelines.

This calculator takes a two-variable point, the distribution's mean, and its 2×2 covariance matrix, then computes the Mahalanobis distance directly. Statisticians, data scientists, and students learning multivariate statistics use it to verify hand calculations or sanity-check outputs from statistical software.

Was this helpful?

You can pick up to 3 reactions.

Be the first to comment.

Popular calculators

All Calculators