Audited 31 Jul 2026·Last updated 28 Oct 2026·3 citations·Tier 2·0 uses

Covariance Calculator

Find the sample (n − 1) and population (n) covariance of two paired lists of numbers, with the pair count, and see why the units make its size hard to read.

Covariance Calculator

Sample covariance
2.25
The sum of paired cross-products divided by n − 1, in the units of X multiplied by the units of Y.
Population covariance
1.8
Pair count
5
Model scope
Descriptive paired-data calculation; covariance retains compound input units and does not establish correlation, causation, stationarity, representativeness, or a population model.

Background.

Covariance asks a narrow question of paired data: when one value sits above its own average, does its partner tend to sit above its average too? For each pair you measure how far x is from the mean of the xs and how far y is from the mean of the ys, then multiply the two distances. Pairs on the same side of both means give positive products; pairs that split give negative ones. Add them up and divide by the number of pairs (or one fewer), and the sign tells you which pattern won.

The sign is the easy part. The size is not, because covariance comes out in the units of x multiplied by the units of y — hours times marks, kilograms times centimetres. Record x in centimetres instead of metres and the covariance grows a hundredfold while the relationship stays exactly as it was. So a covariance of 225 is not necessarily a stronger link than one of 2.25; they may be the same data written differently.

That is why covariance usually feeds something else rather than being reported on its own. Divide it by both standard deviations and you have Pearson's correlation, which is unit-free and runs from −1 to 1. Divide it by the variance of x and you have the slope of the least-squares line. In finance it is the term that decides how much two holdings offset each other's swings.

One trap is worth knowing before you start. Covariance only detects a straight-line tendency. Take x = −2, −1, 0, 1, 2 and y = x², a perfect U-shape: the covariance is exactly 0, even though y is completely determined by x. A small result means no linear trend, not no relationship.

What is covariance calculator?

Covariance is the average of the products of paired deviations: for each observation, (x minus the mean of x) times (y minus the mean of y). Averaged over all n pairs it is the population covariance; divided by n − 1 instead it is the sample covariance, the usual estimate when the pairs are drawn from a larger population. It is symmetric, so swapping the two lists gives the same answer, and the covariance of a variable with itself is simply its variance.

How to use this calculator.

  1. Type or paste the X values into the first box separated by commas, such as 1, 2, 3, 4, 5. Spaces do not matter, but a column pasted one value per line needs commas added between values.
  2. Enter the Y values in the same order, so the third Y belongs to the third X. Both lists need the same length and at least two pairs, and a trailing comma counts as an empty item that will be refused.
  3. Leave out thousands separators: 1,200 is read as two values, 1 and 200. Decimals and scientific notation such as 2.5e-3 are fine.
  4. Use the sample covariance if your pairs are a sample from something larger, the population covariance if they are every case you care about, and check the pair count matches what you meant to enter.

The formula.

s_xy = sum((x_i-xbar)(y_i-ybar))/(n-1)

Sample covariance is s_xy = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1), where x̄ and ȳ are the means of the two lists and n is the number of pairs. Population covariance uses the same sum divided by n. Each term in the sum is one pair's cross-product: positive when both values sit on the same side of their means, negative when they sit on opposite sides, zero when either sits exactly on its mean. Dividing by n − 1 rather than n is Bessel's correction. Deviations measured from the sample's own means come out slightly too small on average, and the smaller divisor compensates so the sample figure is an unbiased estimate of the population value. Because the terms are products, pairs far from both means dominate: one pair 10 units from each mean contributes 100, as much as a hundred pairs one unit away. Adding a constant to every x or y leaves the result unchanged; multiplying every x by k multiplies it by k.

A worked example.

Example

Take five pairs: X = 1, 2, 3, 4, 5 and Y = 2, 3, 5, 4, 6. The X values total 15, so x̄ = 3; the Y values total 20, so ȳ = 4. The deviations from those means are −2, −1, 0, 1, 2 for X and −2, −1, 1, 0, 2 for Y. Multiplying pair by pair gives 4, 1, 0, 0 and 4, a cross-product sum of 9. Divided by n − 1 = 4 that is a sample covariance of 2.25; divided by n = 5 it is a population covariance of 1.8. The pair count shows 5. All of the positive total comes from the two end pairs; the middle pairs contribute nothing because one value in each sits exactly on its mean. That makes the result fragile. Change only the last Y from 6 to 2 and the mean of Y drops to 3.2, the cross-products become 2.4, 0.2, 0, 0.8 and −2.4, and the sample covariance falls to 0.25 — one point wiped out nearly nine-tenths of it.

y Values2, 3, 5, 4, 6
x Values1, 2, 3, 4, 5

Frequently asked questions.

Should I report the sample or the population covariance?
Use the sample figure, dividing by n − 1, when your pairs are a selection from something larger — a survey, a trial, a year of daily readings standing in for the long run. Use the population figure only when the list is the whole group. With five pairs they differ by a factor of 1.25; with 500 pairs by about 0.2%.
Why did my covariance jump when I changed units?
Covariance is measured in x-units times y-units, so rescaling either variable rescales the answer by the same factor. In the example, multiplying every X by 100, as when converting metres to centimetres, turns a sample covariance of 2.25 into 225 without changing the pattern in the data at all.
How do I get a correlation coefficient from covariance?
Divide the covariance by the standard deviation of X times the standard deviation of Y, using the same n or n − 1 throughout. In the example both lists have a sample variance of 2.5, so the correlation is 2.25 ÷ (√2.5 × √2.5) = 0.9, which no longer depends on units.
Can two variables be closely related and still have zero covariance?
Yes. Covariance only picks up a straight-line tendency. For x = −2, −1, 0, 1, 2 and y = x², the positive and negative cross-products cancel exactly and the covariance is 0, although every y is fixed by its x. Plot the pairs before concluding that a small covariance means no relationship.
Why does Excel or NumPy give a different number from mine?
Check which divisor each tool uses. Excel's COVARIANCE.S divides by n − 1, while COVARIANCE.P and the older COVAR divide by n. NumPy's cov divides by n − 1 by default. Compare like with like: the sample result here should match COVARIANCE.S, and the population result COVARIANCE.P.
Where is covariance used in finance?
It sets how two holdings combine. The variance of a two-asset portfolio is a²·Var(X) + b²·Var(Y) + 2ab·Cov(X, Y), so a negative covariance between returns lowers total risk. A stock's beta is its covariance with the market's returns divided by the variance of the market's returns.

How this page was produced

Published by
Quanta Calculator
Primary sources
3 cited below
Method
s_xy = sum((x_i-xbar)(y_i-ybar))/(n-1)
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon