Covariance Calculator
Paste your X and Y values, one pair per row, and the calculator returns the sample covariance, the population covariance and the mean of each variable. Add a third column of weights to get the weighted version.
Related calculators
Created by the Reeliy Editorial Team. Last updated: Oct 19, 2026
What is covariance?
Covariance measures how two variables move together. If values of X that sit above their average tend to be paired with values of Y that sit above their average, the covariance is positive. If high X goes with low Y it is negative, and if there is no systematic pattern it is close to zero.
The size of a covariance depends on the units of both variables, so it tells you the direction of a relationship much more reliably than its strength. A covariance of 8.65 might be a strong relationship in one data set and a weak one in another. To get a unit-free measure, divide by the two standard deviations; that gives the correlation coefficient.
How to use the calculator
- Enter one pair per row: the X value first, then the Y value.
- Separate the two numbers with a space, a tab or a comma. Pasting two spreadsheet columns works as is.
- Optionally add a third number on every row to act as a weight. If you do, every row needs one.
- Press Calculate.
You need at least two rows. Use a dot as the decimal mark and plain numbers only; a header line such as "x,y" is rejected, so leave it out. Blank lines are skipped, and a fourth column is ignored.
The results are the sample covariance (divides by n − 1), the population covariance (divides by n), the mean of X, the mean of Y and the number of pairs. With weights the rows are labelled as weighted values.
Covariance formulas
For n pairs with means x̄ and ȳ, the population covariance divides the sum of cross-products by n, and the sample covariance divides by n − 1 to correct for estimating the means from the same data:
population: σxy = Σ (xᵢ − x̄)(yᵢ − ȳ) ÷ n
sample: sxy = Σ (xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1)
Use the sample version when your pairs are a sample from a larger group, which is the usual case. Use the population version only when the data cover every member of the group of interest.
With weights wᵢ the means become weighted means, x̄ = Σ wᵢxᵢ ÷ Σ wᵢ, and each cross-product is multiplied by its weight. The sum is divided by Σ wᵢ for the population value and by Σ wᵢ − 1 for the sample value, which treats the weights as counts of repeated observations.
Worked example
Take five pairs: (1, 2), (3, 5), (4, 5), (6, 9) and (8, 10). The means are x̄ = 22 ÷ 5 = 4.4 and ȳ = 31 ÷ 5 = 6.2. The table shows each deviation and the product of the two.
| x | y | x − 4.4 | y − 6.2 | product |
|---|---|---|---|---|
| 1 | 2 | −3.4 | −4.2 | 14.28 |
| 3 | 5 | −1.4 | −1.2 | 1.68 |
| 4 | 5 | −0.4 | −1.2 | 0.48 |
| 6 | 9 | 1.6 | 2.8 | 4.48 |
| 8 | 10 | 3.6 | 3.8 | 13.68 |
| sum | 34.60 |
The sum of products is 34.6. Dividing by n − 1 = 4 gives a sample covariance of 8.65; dividing by n = 5 gives a population covariance of 6.92. Both are positive, so larger X values go with larger Y values.
Going one step further, the sample variances are 7.3 for X and 10.7 for Y, so the correlation is 8.65 ÷ (√7.3 × √10.7) ≈ 0.979, and the least-squares slope of Y on X is 8.65 ÷ 7.3 ≈ 1.185.
Where covariance is used
- Portfolio theory: the variance of a portfolio depends on the covariances between asset returns. Assets with low or negative covariance reduce overall risk.
- Regression: the slope of the least-squares line of Y on X equals cov(X, Y) ÷ var(X).
- Principal component analysis: the covariance matrix of many variables is what gets decomposed to find the main directions of variation.
- Signal processing and genetics: covariance between two series or two traits is the starting point for more refined measures of association.
Limits to keep in mind
- Covariance only captures linear co-movement. A perfect U-shaped relationship can have a covariance of zero.
- A single extreme pair can dominate the sum, so look at the data before trusting the number.
- The value changes if you change units, for example from metres to centimetres. Compare relationships with the correlation coefficient instead.
- A covariance of zero means no linear association in the sample, not that the variables are independent.
Frequently asked questions
What is the difference between sample and population covariance?
Both add up the products of deviations from the means. The population covariance divides by n and the sample covariance divides by n − 1. The sample version is slightly larger and is the right choice when your pairs come from a bigger population.
Can covariance be negative?
Yes. A negative covariance means that when X is above its mean, Y tends to be below its mean. For the pairs (2, 7), (4, 5), (6, 4) and (8, 1) the sample covariance is about −6.33.
What does the covariance of a variable with itself equal?
It equals the variance of that variable, because each cross-product becomes a squared deviation.
Why is covariance hard to interpret on its own?
Its magnitude depends on the units and spread of both variables. Dividing by the product of the two standard deviations rescales it to a correlation between −1 and 1, which can be compared across data sets.
References
- Rice, J.A. Mathematical Statistics and Data Analysis, 3rd edition, Cengage (2007), chapter on joint distributions
Cite this calculator and page
If you use this page in your work, you can cite it as:
Reeliy Editorial Team. (2026). Covariance Calculator. Reeliy. https://reeliy.com/calculators/covariance-calculator“Covariance Calculator.” Reeliy, 2026, https://reeliy.com/calculators/covariance-calculator.