Covariance Calculator

Find the sample or population covariance of two variables, see every deviation product and the covariance matrix, and compare it with the correlation.

Separate with commas, spaces or new lines.
Treat the data as a
Population covariance
656.244898
Correlation (r)
0.932covariance on a −1 to 1 scale
Mean of x / y
22.2857 / 408.1429
Variance of x (s²)
38.238095
Variance of y (s²)
17,649.809524
Pairs (n)
7
Sample covariance (sₓᵧ)765.619048positive: x and y tend to rise together
  • Covariance is in x-units × y-units, so its size depends on the units of measurement. Use r to compare strength.

Show the work

  1. Means: x̄ = Σx ÷ n = 156 ÷ 7 = 22.285714; ȳ = 2,857 ÷ 7 = 408.142857
  2. Multiply each pair of deviations, (x − x̄)(y − ȳ), as in the table below: 7 positive and 0 negative products
  3. Add them: Σ(x − x̄)(y − ȳ) = 4,593.714286
  4. Divide by n − 1 = 6: sxy = 4,593.714286 ÷ 6 = 765.619048
  5. Standardize to get the correlation: r = cov ÷ (sxsy) = 765.619048 ÷ (6.183696 × 132.852586) = 0.932
100200300400500600700101520253035xy+ +− +− −+ −(14, 215)(16, 325)(20, 332)(22, 406)(25, 522)(28, 445)(31, 612)
Deviation products
#xyx − x̄y − ȳ(x − x̄)(y − ȳ)
114215−8.2857−193.14291,600.3265
216325−6.2857−83.1429522.6122
320332−2.2857−76.1429174.0408
422406−0.2857−2.14290.6122
5255222.7143113.8571309.0408
6284455.714336.8571210.6122
7316128.7143203.85711,776.4694
Σ1562,857004,593.7143
Covariance matrix (sample)
xy
x38.238095765.619048
y765.61904817,649.809524

Covariance measures how two variables vary together. When large x values tend to come with large y values, the covariance is positive; when large x values come with small y values, it is negative. It is the raw ingredient behind correlation, regression slopes and portfolio risk. This calculator computes the sample or population covariance, lays out every deviation product so you can see which points push it up or down, and draws a scatter plot divided into quadrants at the two means.

How to use the covariance calculator

  1. Enter the X values and the matching Y values in the same order.
  2. Choose Sample (divide by n − 1) or Population (divide by N).
  3. Read the covariance on the tape. The table lists each deviation product, and the 2 × 2 covariance matrix shows the two variances alongside the covariance.
  4. In the scatter plot, points in the upper-right and lower-left quadrants add to the covariance; points in the other two subtract from it.

Covariance formula

sample: sxy = Σ(x − x̄)(y − ȳ) ÷ (n − 1)  ·  population: σxy = Σ(x − μx)(y − μy) ÷ N

Dividing the covariance by both standard deviations turns it into the unit-free correlation:

r = sxy ÷ (sx × sy)

Worked example

An ice cream stand records the daily high temperature (°C) and sales ($) on seven days:

Temperature x 14 16 20 22 25 28 31
Sales y 215 325 332 406 522 445 612
  1. Means: x̄ = 156 ÷ 7 = 22.2857 and ȳ = 2,857 ÷ 7 = 408.1429.
  2. Deviation products: the coldest day contributes (−8.2857)(−193.1429) = 1,600.33 and the hottest (8.7143)(203.8571) = 1,776.47. All seven products are positive.
  3. Their sum is 4,593.71.
  4. Sample covariance: 4,593.71 ÷ 6 = 765.62 (°C × dollars). The population version is 4,593.71 ÷ 7 = 656.24.
  5. With sx = 6.1837 and sy = 132.85, the correlation is 765.62 ÷ (6.1837 × 132.85) = 0.932.

Had the temperatures been recorded in Fahrenheit, every x deviation would be 1.8 times larger and the covariance would become 1,378.11, yet the correlation would still be 0.932. That is the key practical difference between the two measures.

Where covariance is used

Regression slopes

The least-squares slope is the covariance divided by the variance of x: b₁ = sxy ÷ sx². In the example, 765.62 ÷ 38.238 = 20.02, so each extra degree goes with about $20 more in sales. The linear regression calculator fits the full line with standard errors.

Portfolio risk

In finance, the variance of a two-asset portfolio is w₁²σ₁² + w₂²σ₂² + 2w₁w₂σ₁₂, where σ₁₂ is the covariance of the two returns. Assets with negative covariance offset each other, which is the mathematical basis of diversification.

Covariance matrices

With several variables, the covariances are arranged in a symmetric matrix with variances on the diagonal. Techniques such as principal component analysis and multivariate regression start from this matrix.

Covariance versus correlation

Covariance Correlation
Range any real number −1 to 1
Units x-units × y-units none
Changes with unit conversion yes no
Good for comparing strength no yes

Use covariance when you need the quantity in its natural units (for formulas like the slope or portfolio variance) and the correlation coefficient calculator when you want to describe how strong the relationship is. The single-variable counterpart is the variance calculator.

Frequently asked questions

What does a positive or negative covariance mean?

Positive covariance means that when x is above its mean, y tends to be above its mean too, so the variables rise together. Negative covariance means one tends to be above average when the other is below. A covariance near zero means no linear co-movement, though a curved relationship is still possible.

Why is the covariance so large or so small?

Its size depends on the units. Measuring height in centimeters instead of meters multiplies any covariance involving height by 100. That is why covariance values cannot be compared across data sets with different units; the correlation coefficient removes the units and always lies between −1 and 1.

Should I divide by n or n − 1?

Divide by n − 1 for a sample used to estimate the population covariance; this is what Excel's COVARIANCE.S and most statistics software do. Divide by n only when your data are the entire population, matching Excel's COVARIANCE.P.

How is covariance related to variance?

Variance is the covariance of a variable with itself: replace y by x in the formula and you get Σ(x − x̄)² divided by n − 1 or n. That is why the diagonal of a covariance matrix holds the variances.

Last reviewed October 2026 by the CalcFluent editorial team. How we check our calculators.