Covariance Calculator
- The means are x̄ = 6.0000 and ȳ = 7.0000.
- The cross-products of deviations from those means sum to 40.0000.
- Sample covariance divides by n - 1: 40.0000 / 4 = 10.0000; the population version divides by n: 8.0000.
- Correlation puts the covariance on a -1 to 1 scale: r = 1.0000.
This covariance calculator takes two paired lists of numbers and returns the sample covariance, population covariance, and correlation in one pass. It averages the products of paired deviations from the two means: sample covariance divides that sum by n − 1, population covariance by n. For example, X = 2, 4, 6, 8, 10 with Y = 3, 5, 7, 9, 11 move in perfect step — the cross-products sum to 40.0000, giving a sample covariance of 10.0000, a population covariance of 8.0000, and a correlation of exactly 1.0000. Another verified case: X = 1, 2, 3, 4 with Y = 2, 4, 5, 8 gives a sample covariance of 3.1667, a population covariance of 2.3750, and a correlation of 0.9812. If X is constant (5, 5, 5, 5) the covariance is 0.0000 whatever Y does, and correlation cannot be computed because the formula would divide by zero variance.
This method is the accepted standard because it directly captures how two variables co-vary around their respective means. A positive covariance means the series tend to move together, a negative one that they move oppositely; covariance near zero means no linear co-movement, not necessarily no relationship. Because covariance's units are the product of the two variables' units, its size is not comparable across data sets — correlation exists precisely to fix that, rescaling covariance onto the −1 to 1 range. This page shows the formula, step-by-step workings, worked examples, and sources.
Worked examples
Moving in lockstep
Primary result: 10.0000 — Y rises exactly with X, so correlation reaches its maximum of 1.0000. (5 pairs · 2 · 4 · 6 · 8 · 10 · 0 · 0 · 0 · 3 · 5 · 7 · 9 · 11 · 0 · 0 · 0)
| Sample covariance | 10.0000 |
| Population covariance | 8.0000 |
| Correlation (r) | 1.0000 |
Almost a straight line
Primary result: 3.1667 — strong positive co-movement with a correlation of 0.9811. (4 pairs · 1 · 2 · 3 · 4 · 10 · 0 · 0 · 0 · 2 · 4 · 5 · 8 · 11 · 0 · 0 · 0)
| Sample covariance | 3.1667 |
| Population covariance | 2.3750 |
| Correlation (r) | 0.9812 |
No variation, no covariance
Primary result: 0.0000 — a constant X series cannot co-vary with anything, and correlation is undefined. (4 pairs · 5 · 5 · 5 · 5 · 10 · 0 · 0 · 0 · 1 · 2 · 3 · 4 · 11 · 0 · 0 · 0)
| Sample covariance | 0.0000 |
| Population covariance | 0.0000 |
| Correlation (r) | Undefined |
What covariance measures
Covariance measures how two series of numbers move together around their respective means. It does this by averaging the products of paired deviations from those means: for each pair of values, subtract the mean of X from the X value and the mean of Y from the Y value, then multiply those deviations together. Sample covariance divides that sum by n − 1, while population covariance divides it by n. This calculation is the foundation on which both correlation and portfolio variance are built, which is why a covariance calculator often reports all three side by side.
The clearest way to see what covariance captures is through a perfectly aligned example. When X equals 2, 4, 6, 8, 10 and Y equals 3, 5, 7, 9, 11, the two series move in perfect step. The cross-products sum to 40.0000, producing a sample covariance of 10.0000, a population covariance of 8.0000, and a correlation of exactly 1.0000. A slightly messier case shows the same principle at work: X equal to 1, 2, 3, 4 paired with Y equal to 2, 4, 5, 8 yields a sample covariance of 3.1667, a population covariance of 2.3750, and a correlation of 0.9812. The positive values confirm the two series tend to rise and fall together, though not perfectly.
One important edge case arises when one variable does not move at all. If X is constant (5, 5, 5, 5), the covariance is 0.0000 no matter what Y does, and correlation cannot be computed because the formula would require dividing by zero variance. This highlights a key distinction: a covariance near zero means there is no linear co-movement, not necessarily no relationship at all. Two variables can be strongly related in a nonlinear way and still produce a covariance close to zero.
Covariance carries the units of both variables multiplied together, which makes its raw size difficult to interpret and impossible to compare across different data sets. A positive covariance means the series tend to move together, a negative one means they move in opposite directions, and a value near zero means no linear co-movement. Correlation exists precisely to fix the comparability problem, rescaling covariance onto the −1 to 1 range so the strength of the relationship can be judged consistently regardless of the original units.
Sample versus population covariance
Covariance averages the products of paired deviations from the two means. The only difference between the two forms is the divisor: sample covariance divides that sum by n − 1, while population covariance divides it by n. That single change shifts the final value, so a covariance calculator that lets you pick the right mode matters when your numbers must match a textbook or a statistical package.
The shift is easiest to see on clean data. Take X = 2, 4, 6, 8, 10 with Y = 3, 5, 7, 9, 11. The two series move in perfect step, so the cross-products sum to 40.0000. Divide by n − 1 (which is 4) and the sample covariance is 10.0000. Divide by n (which is 5) and the population covariance is 8.0000. Same data, same cross-products — only the divisor changed. The correlation stays exactly 1.0000 in both cases, because correlation rescales covariance onto the −1 to 1 range and ignores the divisor entirely.
A second example shows the same pattern on messier data. With X = 1, 2, 3, 4 and Y = 2, 4, 5, 8, the sample covariance is 3.1667 and the population covariance is 2.3750. The correlation lands at 0.9812, again identical no matter which divisor you choose. A positive covariance means the series tend to move together, a negative one means they move oppositely, and a covariance near zero means no linear co-movement — not necessarily no relationship at all.
Which divisor should you use? Use n − 1 when your data are a sample drawn from a larger group and you want an unbiased estimate of the population covariance. Use n when your data are the entire population and you are describing that population directly, not estimating anything beyond it. Most real-world data sets are samples, so n − 1 is the default in most software and most calculators.
One edge case is worth checking. If X is constant — say X = 5, 5, 5, 5 — the covariance is 0.0000 no matter what Y does, and correlation cannot be computed because the formula would divide by zero variance. Covariance's units are the product of the two variables' units, so its size is not comparable across data sets. Correlation exists precisely to fix that, stripping out units and rescaling onto a fixed range.
Worked examples
The table below shows three verified cases that illustrate how a covariance calculator handles different patterns of paired data. Each row reflects the core rule: covariance averages the products of paired deviations from the two means, with sample covariance dividing that sum by n − 1 and population covariance dividing by n. The first case demonstrates perfect co-movement, the second shows a near-linear relationship, and the third highlights what happens when one variable does not vary at all.
A positive covariance means the series tend to move together, a negative one that they move oppositely, and covariance near zero means no linear co-movement — not necessarily no relationship. The first example makes the positive case vivid: X = 2, 4, 6, 8, 10 paired with Y = 3, 5, 7, 9, 11 moves in perfect step, the cross-products sum to 40.0000, the sample covariance is 10.0000, the population covariance is 8.0000, and the correlation is exactly 1.0000. The second example, X = 1, 2, 3, 4 with Y = 2, 4, 5, 8, is close but not perfectly linear: the sample covariance is 3.1667, the population covariance is 2.3750, and the correlation is 0.9812.
The third case is the constant-X scenario. When X = 5, 5, 5, 5, the covariance is 0.0000 no matter what Y does, and correlation cannot be computed because the formula would divide by zero variance. This is an important boundary: without variation in one variable, there is no linear co-movement to measure.
Remember that covariance's units are the product of the two variables' units, so its size is not comparable across data sets. Correlation exists precisely to fix that, rescaling covariance onto the −1 to 1 range. When you use a covariance calculator, always check both values: covariance tells you the direction of the relationship in the original units, while correlation gives a standardized number you can compare across studies.
| Data (X, Y) | Cross-product sum | Sample covariance | Population covariance | Correlation |
|---|---|---|---|---|
| X = 2, 4, 6, 8, 10; Y = 3, 5, 7, 9, 11 | 40.0000 | 10.0000 | 8.0000 | 1.0000 |
| X = 1, 2, 3, 4; Y = 2, 4, 5, 8 | — | 3.1667 | 2.3750 | 0.9812 |
| X = 5, 5, 5, 5; Y = any | — | 0.0000 | 0.0000 | Cannot compute (zero variance) |
From covariance to correlation
Covariance averages the products of paired deviations from the two means: sample covariance divides that sum by n − 1, population covariance by n. Because covariance's units are the product of the two variables' units, its size is not comparable across data sets. Correlation exists precisely to fix that, rescaling covariance onto the −1 to 1 range. The rescaling is done by dividing the covariance by the two standard deviations — the standard deviation of X and the standard deviation of Y. This single step strips away the units and produces a clean, dimensionless number that always falls between −1 and 1, making it far easier to interpret than raw covariance alone.
To see how this works in practice, consider a verified example. When X = 1, 2, 3, 4 and Y = 2, 4, 5, 8, the data gives a sample covariance of 3.1667 and a population covariance of 2.3750. Dividing by the two standard deviations yields a correlation of 0.9812 — a strong positive linear relationship, but not a perfect one, because the points do not fall on a straight line. A covariance calculator that reports both statistics side by side lets you check this conversion directly.
Contrast that with a case where the two series move in perfect step. When X = 2, 4, 6, 8, 10 and Y = 3, 5, 7, 9, 11, the cross-products sum to 40.0000, giving a sample covariance of 10.0000 and a population covariance of 8.0000. After dividing by the two standard deviations, the correlation comes out to exactly 1.0000. Every increase in X is matched by a proportional increase in Y, so the linear relationship is as strong as it can possibly be.
There is one situation where the conversion breaks down entirely. If X is constant (5, 5, 5, 5), the covariance is 0.0000 whatever Y does, and correlation cannot be computed because the formula would divide by zero variance. A constant variable has no spread, so its standard deviation is zero, and division by zero is undefined. This is not a flaw in the method — it simply reflects the fact that a variable that never changes cannot have a linear relationship with anything else.
Remember that a positive covariance means the series tend to move together, a negative one that they move oppositely, and covariance near zero means no linear co-movement, not necessarily no relationship. Corlation inherits this same limitation: it measures only the strength and direction of a straight-line association. Two variables can have a covariance near zero and still share a strong nonlinear pattern, which neither covariance nor correlation will reveal.
Why covariance has no universal scale
Covariance averages the products of paired deviations from the two means: sample covariance divides that sum by n − 1, population covariance by n. Because each product carries the units of both variables, covariance's units are the product of the two variables' units. If one variable is measured in dollars and the other in years, the covariance comes out in dollar-years. That makes its size hard to interpret on its own, because the number depends entirely on the units you happened to choose. Switch from dollars to cents and the covariance jumps by a factor of 100, even though the underlying relationship has not changed at all.
This is why a covariance calculator will often report a correlation alongside the covariance. Correlation exists precisely to fix the scale problem, rescaling covariance onto the −1 to 1 range. Rescaling either series rescales the covariance but not the correlation. Consider the verified example where X = 2, 4, 6, 8, 10 with Y = 3, 5, 7, 9, 11. These values move in perfect step — the cross-products sum to 40.0000, giving a sample covariance of 10.0000, a population covariance of 8.0000, and a correlation of exactly 1.0000. The covariance value of 10.0000 tells you nothing about how strong the relationship is until you know the units and the spread of the data. The correlation of 1.0000, by contrast, immediately signals a perfect positive linear relationship regardless of units.
The lack of a universal scale also means you cannot compare covariance values across different data sets. A covariance of 10.0000 in one context might reflect a weaker association than a covariance of 3.1667 in another. Take the verified case of X = 1, 2, 3, 4 with Y = 2, 4, 5, 8, which gives a sample covariance of 3.1667, a population covariance of 2.3750, and a correlation of 0.9812. Despite the smaller covariance, the correlation of 0.9812 is nearly as strong as the perfect 1.0000 in the first example. The covariance is smaller partly because the values themselves are smaller, not because the relationship is weaker. Only the correlation lets you make a fair comparison.
A further consequence is that covariance can drop to zero for reasons unrelated to the strength of a relationship. If X is constant — for example, 5, 5, 5, 5 — the covariance is 0.0000 whatever Y does, and correlation cannot be computed because the formula would divide by zero variance. More generally, a positive covariance means the series tend to move together, a negative one that they move oppositely, and covariance near zero means no linear co-movement, not necessarily no relationship. Without the standardized scale that correlation provides, the raw covariance number alone is not enough to judge what is going on.
Covariance in portfolios
Diversification works because combining assets whose returns do not co-vary can reduce the volatility of a portfolio. When two assets move together, a bad period for one tends to coincide with a bad period for the other. When they move oppositely, a drop in one may be offset by a rise in the other. A covariance calculator helps you see these relationships numerically: a positive covariance means the series tend to move together, a negative one that they move oppositely; covariance near zero means no linear co-movement, not necessarily no relationship.
The math behind this is straightforward. Covariance averages the products of paired deviations from the two means: sample covariance divides that sum by n − 1, population covariance by n. Consider a simple verified example. X = 2, 4, 6, 8, 10 paired with Y = 3, 5, 7, 9, 11 move in perfect step. The cross-products sum to 40.0000, giving a sample covariance of 10.0000, a population covariance of 8.0000, and a correlation of exactly 1.0000. In a portfolio, holding two assets like these provides no diversification benefit because they rise and fall in lockstep.
Now compare that with a less perfect pairing. X = 1, 2, 3, 4 with Y = 2, 4, 5, 8 gives a sample covariance of 3.1667, a population covariance of 2.3750, and a correlation of 0.9812. The two series still tend to move together, but not perfectly. The weaker the positive covariance, the more a portfolio may benefit from holding both assets. The key insight is that diversification is not about owning many assets — it is about owning assets whose returns do not strongly co-vary.
One caution is essential. Covariance's units are the product of the two variables' units, so its size is not comparable across data sets. Correlation exists precisely to fix that, rescaling covariance onto the −1 to 1 range. This makes correlation the more practical number when comparing diversification across different asset pairs. Also note that if X is constant (5, 5, 5, 5) the covariance is 0.0000 whatever Y does, and correlation cannot be computed because the formula would divide by zero variance. An asset with no variation does not add to or reduce portfolio volatility through co-movement.
FAQs
How is covariance calculated?
To calculate covariance, average the products of paired deviations from the means. For a sample, divide by n − 1; for a population, divide by n. The verified perfect pair gives a covariance of 10.0000.
What is the difference between sample and population covariance?
The only difference is the divisor. Sample covariance divides by n − 1, while population covariance divides by n. Using the same verified data, the sample covariance is 10.0000 and the population covariance is 8.0000.
What does a covariance of zero mean?
A covariance of zero means there is no linear co-movement in the sample. A constant series, like the verified 5, 5, 5, 5, has zero covariance with everything because it never deviates from its mean.
How is covariance different from correlation?
Correlation is covariance rescaled by the standard deviations onto a range of −1 to 1. The verified near-linear pair has a covariance of 3.1667 but a correlation of 0.9812, showing how rescaling normalizes the value.
Can covariance be negative?
Yes, covariance can be negative. When one series tends to rise as the other falls, the deviation products are mostly negative, which makes the averaged result negative.
Why is correlation undefined for a constant series?
Correlation is undefined for a constant series because its variance is zero. Correlation divides by the standard deviations, and since a constant series has a standard deviation of zero, this would mean dividing by zero.