🧮
🧮 Math & statistics

Covariance Calculator (sample & population, with correlation)

Results update as you type.

Your numbers

Understanding the covariance calculator — concept and principle

This calculator finds the covariance of two paired data sets, both the sample version (divide by n − 1) and the population version (divide by n), plus the direction of the relationship, the means and the Pearson correlation. Use it in statistics homework, finance (how two returns move together) or any study of paired measurements.

6 pairs that rise together6 pairs that rise togetherx̄ = 6ȳ = 75.83Σ(x − x̄)(y − ȳ)155Population155 ÷ 6 = 25.83Correlation r0.9976Sample covariance155 ÷ 5 = 31
Points in the green quadrants add positive products, so covariance is positive.

How it is calculated

Sample covariance = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1)

Population covariance = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ n

Correlation r = covariance ÷ (sₓ × s_y)

The principle

For each pair, (x − x̄)(y − ȳ) is positive when both values are on the same side of their means and negative when they are on opposite sides. Averaging those products shows whether the variables tend to move together (positive), in opposite directions (negative), or not in a linear way (near zero). Dividing by n − 1 instead of n corrects for the fact that the means were estimated from the same data, making the sample covariance an unbiased estimate. Because covariance carries the units of both variables, its size is hard to judge; the correlation rescales it to between −1 and 1.

Worked example

Default inputs: X = 2, 4, 5, 7, 8, 10 and Y = 62, 68, 71, 80, 83, 91.

  1. Means: x̄ = 36 ÷ 6 = 6; ȳ = 455 ÷ 6 = 75.83333333; 6 pairs.
  2. Sum of cross-products Σ(x − x̄)(y − ȳ) = 155.
  3. Sample covariance = 155 ÷ 5 = 31.
  4. Population covariance = 155 ÷ 6 = 25.83333333.
  5. Correlation r = 0.9975532341: positive — X and Y tend to rise together.

How to read the result

The sign is the most useful part of a covariance: here X and Y rise together. The size, 31, is in units of X times units of Y, so it changes if you change units (for example from hours to minutes). To judge strength, look at r: 0.998 is an almost perfect straight-line relationship. A covariance near zero means no linear relationship, though a curved one may still exist.

Common mistakes

Keep in mind: Outliers can dominate a covariance. Plot the data before relying on the number.

Frequently asked questions

What is the difference between covariance and correlation?

Correlation is covariance divided by both standard deviations, so it has no units and lies between −1 and 1.

When do I use n − 1?

For a sample used to estimate a population; use n when your data are the whole population.

What does a negative covariance mean?

When one variable is above its mean, the other tends to be below its mean.

Sources: NIST/SEMATECH e-Handbook of Statistical Methods, §6.5.4.1 Mean Vector and Covariance Matrix

Checked 9 Nov 2026. NIST/SEMATECH e-Handbook of Statistical Methods, §6.5.4.1 Mean Vector and Covariance Matrix (COV = Σ(Xᵢ − x̄)(Yᵢ − ȳ)/(n − 1), unbiased sample variance–covariance matrix).

🧮 All math & statistics tools →🌍 Calculators by country →