Covariance Calculator

Written by Thierno Sadou Diallo, formula verified per our methodology • Last checked on 9/10/2026

The sample covariance measures how two variables vary together: a positive covariance means they tend to increase together, a negative one that they vary in opposite directions. For the pairs (1,2), (2,4), (3,5), (4,4), (5,5), the covariance is 1.5.

Explanation

Covariance quantifies how two variables vary jointly: a positive covariance means that when one increases, the other tends to increase too; a negative covariance means they move in opposite directions; a covariance close to zero suggests no clear linear relationship between the two. Its main limitation is that its magnitude depends directly on the units and scale of the measured data, which makes it hard to interpret or compare from one dataset to another — it is precisely to solve this problem that the Pearson correlation coefficient normalizes covariance by the standard deviations of the two variables, obtaining a value always between −1 and 1, independent of the units used. Covariance nonetheless remains the fundamental building block behind Pearson correlation and simple linear regression (where it appears directly in calculating the slope of the line), even though it was until now never displayed as a standalone result on this site.

Example: pairs (1,2), (2,4), (3,6)

Inputs

x = 1, 2, 3. y = 2, 4, 6 (perfectly linear relationship, y = 2x).

Calculation

Mean of x = 2, mean of y = 4. Covariance = [(1−2)(2−4) + (2−2)(4−4) + (3−2)(6−4)] ÷ (3−1) = [2 + 0 + 2] ÷ 2 = 2.

Result

The covariance of these two perfectly linearly related series is 2.

Frequently asked questions

Why divide by n−1 rather than by n?

This correction, called Bessel's, compensates for a statistical bias that appears when estimating the variability of an entire population from a mere sample: dividing by n−1 rather than by n gives a less biased estimate, particularly for small samples. It is the same convention used by this site's sample variance and standard deviation calculator.

Does a high covariance mean a strong relationship between the two variables?

Not necessarily: the value of covariance depends directly on the scale of the data (values in thousands will give a much larger covariance than the same data in units, without the strength of the relationship having changed). This is why the Pearson correlation coefficient, which normalizes covariance, is generally preferred to judge the strength of a linear relationship.

Does a covariance of zero mean there is no relationship between the two variables?

No, a zero covariance only indicates the absence of a linear relationship between the two variables — a strong non-linear relationship (for example U-shaped) can perfectly well produce a covariance close to zero while clearly existing. Covariance detects only linear trends, not more complex relationships.

Related resources

Similar calculators