Covariance Calculator

Calculate the covariance between two variables (Sample or Population).

Calculator by SuperCalX: formulas, worked examples and 250+ free calculators.

Your values

Result

Enter your values and the result appears here.

Analysis

Interpretation of the current calculator output

Enter values to see detailed analysis and insights.

How to Use

Step-by-step instructions
  1. 1Enter the values for variable X.
  2. 2Enter the values for variable Y.
  3. 3Select Sample or Population.
  4. 4The calculator will compute the covariance.

Covariance Formula

Covariance measures how two variables change together. A positive covariance indicates that the variables tend to move in the same direction, while a negative covariance indicates they move in opposite directions. For population covariance, divide by n instead of n-1.
Cov(X,Y) = Sum(x - xBar)(y - yBar) / (n - 1)

Variables:

x, yIndividual data points
xBar, yBarMeans of X and Y
nSample size

Example

Simple Dataset

Inputs:

X:2, 4, 6
Y:5, 10, 15

Steps:

  1. 1.Means: xBar = 4, yBar = 10
  2. 2.Deviations X: -2, 0, 2
  3. 3.Deviations Y: -5, 0, 5
  4. 4.Products: 10, 0, 10
  5. 5.Sum: 20
  6. 6.Sample Covariance: 20 / (3-1) = 10
Result:
10

Covariance Calculator: the short answer

Covariance shows whether two variables move together: sample Cov(X, Y) = Σ(x − x̄)(y − ȳ) ÷ (n − 1). For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5, the sum of cross-products is 6, so the sample covariance is 1.5 (population covariance 1.2). Positive means they tend to rise together.

  • The sign is meaningful; the size depends on the units, so it is hard to compare.
  • Correlation is covariance scaled to −1…+1: r = Cov ÷ (sx × sy).
  • Covariance matrices are central to portfolio risk and machine learning.

By the SuperCalX team · Reviewed by Dr. Ahmed Mortuza Saleque, founder and editor · Last reviewed · How we check our calculators

Sample or population?

Divide by n − 1 when your data are a sample from a bigger group, and by n when you have the entire population. With small samples the difference is noticeable: 1.5 vs 1.2 above.

Covariance in finance

Two assets with negative covariance tend to offset each other, which lowers portfolio risk. Beta, used in the CAPM calculator, is the covariance of a stock with the market divided by the market's variance.

Worked examples

x = 1–5, y = 2, 4, 5, 4, 5

  1. Cross-products: (−2)(−2) + (−1)(0) + 0(1) + 1(0) + 2(1) = 6.
  2. Sample: 6 ÷ 4 = 1.5. Population: 6 ÷ 5 = 1.2.

Sample covariance 1.5.

Common mistakes

  • Comparing covariances measured in different units.

Covariance Calculator FAQ

What is the difference between covariance and correlation?

Correlation is standardised covariance, so it is unit-free and always between −1 and 1. Use the correlation coefficient calculator to compare strengths.

Can covariance be negative?

Yes, when one variable tends to be above its mean while the other is below.

Add this calculator to your website

Teachers, bloggers and businesses can show the Covariance Calculator on their own pages for free. Copy this code and paste it into your page's HTML:

Please keep the credit link so readers can find the formula, worked examples and guide.