statcompute

Regression & correlation

Covariance Calculator

Whether two variables move together — before dividing out the units.

Updated August 2026Runs in your browser — nothing is uploadedVerified against R
One value per line, or separated by commas, tabs or spaces. A header row is ignored.
One value per line, or separated by commas, tabs or spaces. A header row is ignored.

The calculation runs in your browser, so this box needs JavaScript. The formula, the worked example and the interpretation below do not.

01

How to read this result

Only the sign is directly interpretable. Positive means the two variables tend to be above their means together; negative means one tends to be high when the other is low; zero means no linear co-movement.

The magnitude depends on the units. Multiply x by a thousand and the covariance multiplies by a thousand too. That is why covariance is almost never quoted on its own — divide it by both standard deviations and you get the correlation, which is unitless and bounded.

Think in quadrants. Draw lines at the two means. Points in the upper-right and lower-left contribute positive products; the other two contribute negative ones. Covariance is the average of those products, so it measures which pair of quadrants dominates.

Zero covariance does not mean independence. Independent variables have zero covariance, but the reverse fails: a symmetric U-shaped relationship has covariance zero and is anything but independent.

02

The formula

covsample=(xix¯)(yiy¯)n1covpop=(xix¯)(yiy¯)n

The n − 1 is Bessel's correction, exactly as in the variance — and the covariance of a variable with itself is its variance.

03

Worked example

Covariance of the ten towns

The same paired data as the correlation example:

x: 43, 21, 25, 42, 57, 59, 247, 32, 40, 55 y: 99, 65, 79, 75, 87, 81, 486, 71, 84, 90

  1. Take both means.
    x̄ = 62.1, ȳ = 121.7
  2. For each pair, multiply the two deviations.
    (43 − 62.1)(99 − 121.7) = 433.6, and so on
  3. Add all ten products.
    Σ = 75,533.3
  4. Divide by n − 1 = 9.
    cov = 8,392.59
  5. Divide by both standard deviations to get the correlation.
    8392.59 / (66.25 × 128.37) = 0.987
sample covariance 8,392.6population covariance 7,553.3correlation 0.987direction positive

8,392 means nothing on its own — it would be 8.4 million if x were measured in thousandths. The 0.987 that comes from dividing it by both standard deviations is the number worth reporting.

Checked against R's cov and cor.

The calculator above is loaded with these numbers by the Load the worked example button.

04

Assumptions, and when to use something else

Paired numeric observations in matching order, and independence between pairs. Covariance describes linear co-movement only, and — like the variance it generalises — it is extremely sensitive to outliers, because each contribution is a product of two deviations.

  • You want a unitless measureCorrelation coefficientCovariance divided by both standard deviations.
  • You want to predict one variable from the otherLinear regressionThe slope is the covariance divided by the variance of x.
  • You want the spread of one variableVariance calculatorThe covariance of a variable with itself.
05

Questions people ask

What is the difference between covariance and correlation?

Correlation is covariance divided by both standard deviations. That division removes the units and bounds the result between −1 and 1, which makes correlations comparable across data sets while covariances are not.

Can covariance be negative?

Yes — it means the variables move in opposite directions: when one is above its mean the other tends to be below. Only the sign and the correlation are interpretable; the magnitude depends on the units.

What does a covariance of zero mean?

No linear co-movement. It does not mean the variables are independent: a perfectly symmetric curved relationship has zero covariance.

Why is the covariance of a variable with itself the variance?

Put y = x in the formula and you get Σ(x − x̄)²/(n − 1), which is exactly the variance. Covariance is the general case and variance the special one.