Covariance calculator

This covariance calculator measures how two variables move together. Paste the X values and the matching Y values to get the sample covariance, the population covariance and the correlation that goes with them.

Your numbers are calculated in your browser. Nothing you enter is sent or stored.

Covariance calculatorOr describe it in Studio →

Each X is paired with the Y in the same position.

Sample covariance

17

Population covariance
13.6
Mean of X
6
Mean of Y
7
Sum of products
68
Pairs
5
Correlation (r)
0.9815

Positive: the two variables tend to rise together.

To report

cov(X, Y) = 17 (sample, n = 5); population 13.6

Check your result: the sample and population versions differ only by dividing by n − 1 or n: 17 × 4 ÷ 5 = 13.6 in the example. The covariance of X with itself is its variance, 10 for X = 2, 4, 6, 8, 10, and the covariance always has the same sign as r.
sample covariance in the worked example
17
sample covariance in the worked example
population covariance
13.6
population covariance
correlation for the same pairs
0.981
correlation for the same pairs
  • Sample (n − 1) and population (n)
  • Means and sum of products
  • Correlation shown alongside
  • Paste from a spreadsheet
  • Runs in your browser, free

01

Covariance formula

sample: cov(X, Y) = Σ (x − x̄)(y − ȳ) ÷ (n − 1)

population: cov(X, Y) = Σ (x − x̄)(y − ȳ) ÷ n

x̄ and ȳ are the two means. Use the sample version when your pairs are a sample from something larger, which is the usual case.

residualxy
A fitted line and a residual. Each dot is one pair of measurements. The line is the one that makes the squared vertical distances as small as possible. A residual, the dashed segment, is the distance from a point to the line; the tighter the points hug the line, the closer r is to 1 or −1.

02

Worked example

X = 2, 4, 6, 8, 10 and Y = 1, 3, 7, 9, 15. The means are 6 and 7.

x − x̄y − ȳProduct
−4−624
−2−48
000
224
4832

sum of products = 68; sample covariance = 68 ÷ 4 = 17

The population covariance is 68 ÷ 5 = 13.6, and r = 0.981.

03

Covariance vs correlation

The sign of the covariance tells you the direction of the relationship, but its size depends on the units: measuring height in centimetres instead of metres multiplies it by 100. Dividing by both standard deviations removes the units and gives the correlation coefficient, which always lies between −1 and 1.

04

Common mistakes with covariance

  • Reading its size as strength. Multiplying every X by 100, as when metres become centimetres, turns 17 into 1,700, while r stays 0.981.
  • Mixing up n and n − 1. With five pairs the population covariance (13.6) is 20% smaller than the sample covariance (17).
  • Pairs out of order. Listing Y the other way round (15, 9, 7, 3, 1) keeps both means but turns the covariance into −17.

Trust

How this page is checked

  • The calculation runs on code with automated tests against worked reference values. Every number in the examples on this page was produced by that same code, not typed by hand.
  • The formulas and conventions used are stated on the page, so you can reproduce the result yourself or compare it with your own software.
  • Last reviewed by the Sciloom team, Zebra Nine Studio Inc. It is a tool for research and teaching, not a substitute for a statistician, a validated lab method or medical advice.

Cite this page

Sciloom. (2026). Covariance calculator. Zebra Nine Studio Inc. https://sciloom.si/covariance-calculator

Read the full methodology · Who makes Sciloom

Frequently asked questions

What does a positive covariance mean?

Above-average values of one variable tend to go with above-average values of the other. A negative covariance means they tend to move in opposite directions.

Why divide by n − 1?

Because the means are estimated from the same data, dividing by n would underestimate the covariance on average. Dividing by n − 1 corrects that for a sample.

Does zero covariance mean the variables are independent?

No. It means there is no linear relationship. A curved relationship, such as a U shape, can give a covariance of zero.

What is the unit of covariance?

The product of the two units, for example cm × kg. That is why it is hard to interpret on its own and correlation is usually reported instead.

Want a unit-free measure with a p value? Use the correlation coefficient calculator.
Free to start, no sign-up.
Back to the tool ↑

More research tools