Covariance Calculator
Comma or space separated. Example: 10,34,23,54,9
Covariance tells you the direction two variables move in together. Positive means they rise and fall together. Negative means one goes up while the other goes down. Enter your paired X and Y values above, choose sample or population, and this covariance calculator returns the answer with every step shown: the means, the deviation table, the sum of products, and the final division. Below you will find the formulas written out, three fully worked examples, how to do it in Excel, and how covariance differs from correlation. The default numbers in the tool (X = 10, 34, 23, 54, 9 and Y = 4, 5, 11, 15, 20) return a sample covariance of 5.75, and you can see exactly how that number is built.
What is covariance?
Covariance is a number that shows whether two variables move in the same direction or opposite directions. It is one of the first things statisticians check before running correlation or regression.
There are three cases:
- Positive covariance: when one variable goes up, the other tends to go up too. Example: hours studied and exam scores.
- Negative covariance: when one variable goes up, the other tends to go down. Example: price of a product and quantity people buy.
- Zero (or near zero) covariance: no clear straight-line pattern between the two.
One thing covariance does not tell you is strength. A covariance of 500 is not automatically stronger than a covariance of 5, because the number depends on the scale of your data. For strength on a fixed scale from minus one to one, you need the correlation coefficient calculator instead. Covariance answers direction. Correlation answers strength.
What is the covariance formula?
The formula changes slightly depending on whether your data is a full population or a sample from a larger group. Both are built from deviations from the mean, the same building block used in the variance calculator.
Population covariance formula
Cov(X, Y) = Σ (Xᵢ − µᴼ)(Yᵢ − µᴾ)N
Sample covariance formula
Cov(X, Y) = Σ (Xᵢ − X̄)(Yᵢ − Ȳ)n − 1
Here is what each symbol means:
- Xᵢ and Yᵢ are the individual paired data values
- X̄ and Ȳ (or µᴼ and µᴾ) are the means of X and Y
- Σ means add up everything that follows
- N is the population size, n is the sample size
The only difference between the two formulas is the bottom. Population divides by N. Sample divides by n minus 1. That minus one is called Bessel’s correction, and it makes the sample estimate more accurate for the true population value.
How do you calculate covariance step by step?
Five steps, no shortcuts:
- Pair your data. Line up each X value with its matching Y value. Order matters. If the pairs are wrong, the answer is meaningless.
- Find both means. Add up the X values and divide by the count. Do the same for Y.
- Find each deviation. Subtract the X mean from every X value, and the Y mean from every Y value.
- Multiply the deviations. For each row, multiply the X deviation by the Y deviation.
- Add and divide. Sum all the products. Divide by n minus 1 for a sample, or by N for a population.
Covariance calculation examples
Three worked examples, from simple to real. Every number below is checked against the calculator above.
Example 1: A clean starter (X = 2, 4, 6 and Y = 3, 5, 7)
Means: X̄ = (2 + 4 + 6) ÷ 3 = 4, and Ȳ = (3 + 5 + 7) ÷ 3 = 5.
| X | X − X̄ | Y | Y − Ȳ | Product |
|---|---|---|---|---|
| 2 | −2 | 3 | −2 | 4 |
| 4 | 0 | 5 | 0 | 0 |
| 6 | 2 | 7 | 2 | 4 |
| Sum of products | 8 | |||
Sample covariance = 8 ÷ (3 − 1) = 4. Positive, so X and Y move together.
Example 2: The calculator’s default data (X = 10, 34, 23, 54, 9 and Y = 4, 5, 11, 15, 20)
Means: X̄ = 130 ÷ 5 = 26, and Ȳ = 55 ÷ 5 = 11.
| X | X − X̄ | Y | Y − Ȳ | Product |
|---|---|---|---|---|
| 10 | −16 | 4 | −7 | 112 |
| 34 | 8 | 5 | −6 | −48 |
| 23 | −3 | 11 | 0 | 0 |
| 54 | 28 | 15 | 4 | 112 |
| 9 | −17 | 20 | 9 | −153 |
| Sum of products | 23 | |||
Sample covariance = 23 ÷ (5 − 1) = 5.75. If you treat the same numbers as a full population, you divide by 5 instead: 23 ÷ 5 = 4.6.
Example 3: Sample vs population on the same data (X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5)
Means: X̄ = 3, Ȳ = 4. Sum of products works out to 6.
- Sample covariance = 6 ÷ (5 − 1) = 1.5
- Population covariance = 6 ÷ 5 = 1.2
Notice the sample value is always a little larger than the population value on the same data, because you divide by a smaller number.
Sample covariance vs population covariance: which one do you use?
Use population covariance only when your data covers every member of the group you care about. Every student in one class. Every product in one shipment. Nothing left out.
Use sample covariance when your data is a subset drawn from a bigger group, which is almost every real situation. Survey responses, a batch of measurements, a slice of historical prices. When in doubt, use sample. That is why the calculator defaults to sample and why Excel’s most common function is the sample version.
How do you find covariance in Excel?
Excel has a built-in function for each type, so you never have to build the table by hand.
- Sample:
=COVARIANCE.S(A1:A5, B1:B5) - Population:
=COVARIANCE.P(A1:A5, B1:B5)
Both ranges must hold paired values in the same order, and both must be the same length. The three mistakes that trip people up: picking the population function when they have a sample, selecting ranges of different sizes, and leaving blank cells inside a range. Google Sheets uses the same two function names, so the formulas above work there without changes.
How do you interpret a covariance result?
Read the sign first, then remember the limit:
- Positive number: a direct relationship. Both variables tend to rise and fall together.
- Negative number: an inverse relationship. One rises while the other falls.
- Close to zero: little or no straight-line relationship.
The size of the number is not a measure of how strong the link is. A big covariance can just mean your data uses big units. To compare strength across different datasets, convert to correlation, which always lands between minus one and one.
Covariance vs correlation: what is the difference?
They answer two different questions. Covariance gives direction on an open scale. Correlation gives direction and strength on a fixed scale. Correlation is actually built from covariance, so they are closely linked.
| Feature | Covariance | Correlation |
|---|---|---|
| What it measures | Direction of the relationship | Direction and strength |
| Range of values | Any number, positive or negative | Fixed from −1 to +1 |
| Affected by units/scale | Yes | No, it is standardized |
| Compare across datasets | Hard | Easy |
| Best used for | A first look at direction | Measuring and comparing strength |
Rule of thumb: use covariance to get the direction quickly, then switch to correlation when you need to judge how strong that relationship really is.
What are the most common covariance mistakes?
- Wrong formula for the data type. Using the population formula on a sample understates the estimate. Sample data needs n minus 1.
- Skipping the mean subtraction. Covariance is built entirely on deviations from the mean. Miss that step and the whole thing collapses.
- Mismatched pairs. If an X value lines up with the wrong Y value, the result has no meaning.
- Reading size as strength. A large covariance often just reflects large units, not a strong relationship.
- Confusing it with correlation. Covariance is direction only. Correlation adds strength.
Try these next
- Linear Regression Calculator
- Scatter Plot Maker
- Standard Deviation Calculator
- Mean, Median, Mode, Range Calculator