Skip to content
MoneyDeck

Covariance Calculator

Measure how two variables move together, with a step-by-step table

Updated · Free, no signup

Separate numbers with commas, spaces or new lines.

Sample covariance (n − 1)

34.5

Population covariance (n)

27.6

Pearson correlation r

0.998

Mean of X

6

Mean of Y

78

Sample SD of X

3.1623

Sample SD of Y

10.9316

Pairs used (n)

5

  • Positive covariance: when X is above its mean, Y tends to be above its mean too.
  • Covariance depends on the units of X and Y; the unit-free correlation r = 0.998 shows the strength of the linear relationship.

Cross-product of deviations for each pair

Step-by-step deviations

#xyx − x̄y − ȳ(x − x̄)(y − ȳ)
1265-4-1352
2470-2-816
3678000
48852714
5109241456
Σ3039000138

About the Covariance Calculator

This covariance calculator measures how two variables move together. Paste the X values and the matching Y values and it returns the sample covariance (dividing by n − 1), the population covariance (dividing by n), both means, both standard deviations and the Pearson correlation coefficient. A step-by-step table lists each deviation from the mean and the cross-product, so you can follow — or hand in — the working.

Covariance is the building block of correlation, regression slopes and portfolio risk. Students use this tool for statistics homework, investors use it to see whether two assets’ returns rise and fall together, and analysts use it as a quick check before fitting a model. A positive covariance means the variables tend to be above their means at the same time; a negative one means they move in opposite directions.

Values can be separated by commas, spaces or new lines, and the two lists must have the same length — if they differ, the calculator pairs values in order and ignores the extras, with a note. Use the sample covariance when your data are a sample from a larger population (the usual case) and the population version when you have every value.

With the default inputs, the sample covariance (n − 1) is 34.5. Change any value above to recalculate instantly.

How to use the covariance calculator

  1. 1Paste the X values into the first box.
  2. 2Paste the matching Y values, in the same order, into the second box.
  3. 3Read the sample covariance (or the population covariance if you have the whole population).
  4. 4Check the correlation r for a unit-free measure of strength, and the table for the working.

Formula and method

Sample: s_xy = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1) Population: σ_xy = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ n r = s_xy ÷ (s_x · s_y)

For each pair, subtract the mean of X from x and the mean of Y from y, then multiply the two deviations. Pairs where both values are on the same side of their means give positive products; pairs on opposite sides give negative products. Summing the products and dividing by n − 1 gives the sample covariance, an unbiased estimate of the population covariance (Bessel’s correction). Dividing by n instead gives the population covariance.

Covariance is measured in the units of X times the units of Y, so its size is hard to interpret on its own. Dividing by the product of the two standard deviations produces the Pearson correlation coefficient r, which always lies between −1 and +1.

xᵢ, yᵢ
The i-th paired observations
x̄, ȳ
Means of X and Y
n
Number of pairs
s_x, s_y
Sample standard deviations of X and Y

Worked examples

Hours studied vs exam score

The means are 6 hours and 78 points. The cross-products are 52, 16, 0, 14 and 56, summing to 138. Sample covariance = 138 ÷ 4 = 34.5 and population covariance = 138 ÷ 5 = 27.6; r ≈ 0.998 shows an almost perfectly linear link.

Monthly returns of two stocks (%)

Both stocks average a positive return and move up and down in the same months. The sum of cross-products is 5.26, so the sample covariance is 5.26 ÷ 5 = 1.052 (%²), which feeds directly into portfolio variance calculations.

Price vs units sold (negative relationship)

As price rises from 10 to 40, units sold fall. The deviations have opposite signs, the cross-products sum to −485 and the sample covariance is −485 ÷ 3 ≈ −161.67.

Frequently asked questions

What does covariance tell you?+

Covariance shows the direction of the linear relationship between two variables. Positive means they tend to rise together, negative means one tends to fall as the other rises, and near zero means no linear pattern.

Should I use sample or population covariance?+

Use the sample covariance (divide by n − 1) when your data are a sample used to estimate a larger population, which is almost always the case. Use the population version (divide by n) only when the data include every member of the population.

What is the difference between covariance and correlation?+

Correlation is covariance divided by the product of the two standard deviations. That removes the units, so correlation always lies between −1 and +1 and can be compared across data sets, while covariance cannot.

Can covariance be negative?+

Yes. A negative covariance means that when one variable is above its mean the other tends to be below its mean, such as price and quantity demanded. There is no lower or upper limit on its value.

How is covariance used in finance?+

Portfolio variance depends on the covariances between asset returns. Combining assets with low or negative covariance reduces overall risk, and beta is the covariance of a stock with the market divided by the market variance.

Related tools