Covariance tells you whether two variables tend to move together, and in which direction. When covariance is positive, the two series rise and fall in the same pattern; when it is negative, they move in opposite directions; and when it is near zero, they show no linear relationship at all. This covariance calculator takes two data series, aligned pair by pair, and instantly returns both the sample covariance and the population covariance, along with the means, the number of pairs, and the correlation coefficient so you can judge how strong the relationship really is.
Unlike correlation, covariance is not a bounded number. Its units are the product of the units of your two variables, so a covariance of 485,000 between ad spend and sales means something different from a covariance of 5 between two small integer series. That is exactly why the calculator also reports the correlation coefficient (r), which rescales covariance onto a tidy −1 to +1 range.
How to Use
- Set the Number of Pairs to how many (x, y) data points you have (1 to 7). Then type each X value into its own numbered box — put the first X in X1, the second in X2, and so on. Decimals and negative numbers are both allowed.
- Type the matching series into the Y1, Y2, … boxes. The values must line up position by position: X1 pairs with Y1, X2 with Y2, and so on. If your Number of Pairs is 5, only fill X1 through X5 and Y1 through Y5; you can leave X6, X7, Y6 and Y7 empty, because the calculator uses exactly the number of pairs you set.
- Choose the Covariance Type (ddof). Leave it on
1for sample covariance, which divides by N−1 and is the right choice when your data is a sample drawn from a larger group. Set it to0for population covariance, which divides by N and is correct when your data covers the entire group you care about. - Read the result card. The highlighted Covariance value reflects the ddof you chose, while Sample Covariance and Population Covariance are both always shown so you can compare them directly. A positive number means the series move together; a negative number means they move in opposite directions; near zero means no straight-line relationship.
- Check the Correlation Coefficient (r). Covariance can be huge or tiny depending on your units; r normalizes it so you can compare relationships on a common −1 (perfect inverse) to +1 (perfect together) scale.
The calculator uses exactly the Number of Pairs you set, reading the first N X boxes and the first N Y boxes as a matched list. You do not need to paste a comma-separated sequence — just type one number into each numbered box.
The Covariance Formula
Covariance measures the average product of the deviations of each variable from its own mean:
Cov(X, Y) = Σ (xᵢ − meanX)(yᵢ − meanY) / (N − ddof)
Where:
- xᵢ and yᵢ are the paired observations.
- meanX is the average of the X series, and meanY is the average of the Y series.
- N is the number of paired observations.
- ddof is the "degrees of freedom" correction:
0for population covariance (divide by N) and1for sample covariance (divide by N−1, the Bessel correction).
The intuition is simple. For each pair, ask how far X is from its average and how far Y is from its average, then multiply those two deviations. When both variables are above their means at the same time, the product is positive; when one is above and the other below, the product is negative. Summing all those products and dividing by N (or N−1) gives the covariance.
Worked example on X = 1, 2, 3, 4, 5 and Y = 2, 4, 6, 8, 10. The mean of X is 3 and the mean of Y is 6. The summed product of deviations is 20. Dividing by N = 5 gives a population covariance of 4.0, and dividing by N−1 = 4 gives a sample covariance of 5.0. Because Y doubles X, the correlation coefficient is +1.0 — a perfect positive relationship.
Sample vs Population: Which Do You Need?
This is the single most common source of confusion. Population covariance is used when your data set is the entire group you are studying — say, every monthly sales figure your business has ever recorded. You divide by N because you have measured everyone.
Sample covariance is used when your data is a subset drawn to estimate a larger unknown group — for example, 12 months of returns used to estimate the true long-run relationship between two stocks. Dividing by N−1 removes a small downward bias and is the default in Excel's COVARIANCE.S, R's cov(), and numpy's sample estimator. The two numbers differ slightly (4.0 versus 5.0 in the example above), and the gap shrinks as N grows.
Examples
Example 1 — Perfect inverse relationship. X = 1, 2, 3, 4, 5 and Y = 10, 8, 6, 4, 2. Here Y falls by exactly the amount X rises. The summed cross-deviation is −20, so population covariance is −4.0 and sample covariance is −5.0, with a correlation of −1.0. The negative sign tells the whole story: the two series move in opposite directions.
Example 2 — Advertising spend versus sales (in dollars). A small business records weekly ad spend of $200, $350, $500, $650, $800, $950, $1,100 and the corresponding sales of $1,800, $2,600, $3,100, $3,900, $4,700, $5,200, $6,000. The mean ad spend is $650 and mean sales are $3,900. The sample covariance comes out to $485,000 and the population covariance to about $415,714, with a correlation of roughly +0.9986. The large positive covariance confirms that higher ad spend is strongly associated with higher sales — though remember that covariance alone does not prove causation.
Example 3 — Near-zero relationship. X = 1, 2, 3, 4, 5 and Y = 5, 1, 7, 2, 4, where Y jumps around independently of X. The positive and negative deviation products cancel out, pushing covariance close to zero and the correlation near zero as well. This is the signature of two variables with no meaningful linear link.
FAQ
What is the difference between covariance and correlation?
Covariance measures the direction of the linear relationship between two variables and is measured in the product of their units — dollars squared, percentage-points times dollars, and so on. Correlation normalizes covariance by the standard deviations of both variables, producing a value between −1 and +1 that measures both direction and strength. Covariance tells you "do they move together?"; correlation tells you "how tightly?".
How do I interpret a negative covariance?
A negative covariance means the two variables tend to move in opposite directions: when one is above its average, the other tends to be below its average. For example, the price of a bond and its current interest rate often show negative covariance — as rates rise, bond prices fall. The farther the value sits below zero, the stronger the inverse linear relationship.
Should I use sample covariance or population covariance?
Use population covariance (ddof = 0) when your data set is the complete group you want to describe. Use sample covariance (ddof = 1) when your data is a sample used to estimate a larger, unknown population. Sample covariance divides by N−1 to correct for bias, which is why statistical software defaults to it.
What does a covariance of zero actually mean?
A covariance of (or near) zero means there is no linear relationship between the two variables — knowing the value of one gives you no information about the direction of the other. Note that the variables could still be related in a non-linear way; covariance only captures straight-line (linear) association.
Can covariance tell me if one variable causes the other?
No. Covariance and correlation both measure association, not causation. Two variables might move together because one drives the other, because a hidden third factor drives both, or purely by coincidence. Use controlled experiments, domain knowledge, and time-series or regression analysis before making causal claims.
Why is my covariance so large or so small?
Covariance scales with the units of your data. Multiplying every X value by 1,000 multiplies the covariance by 1,000. That is why comparing covariances across different data sets is misleading — always look at the correlation coefficient (r), which is unit-free, when you want to compare the strength of relationships.
Disclaimer
This covariance calculator is provided for informational purposes only and does not constitute financial, statistical, or investment advice. Results are computed directly from the values you enter using the standard covariance formula, and they assume the X and Y series are paired correctly and contain only numeric data. Always verify calculations against an independent tool or a qualified analyst before using them in research, modeling, or investment decisions. For our editorial standards see the About page, and for data handling see the Privacy Policy; we do not store the data points you enter on this page.