Skip to content
Statistics

Covariance Calculator

Covariance measures how two variables move together: positive when they rise and fall in sync, negative when one climbs as the other drops. Paste two equal-length, comma-separated lists below to get population and sample covariance, the Pearson correlation coefficient, standard deviations, variances, and a full pair-by-pair breakdown table.

Your details

Separate values with commas, spaces or new lines.
Must contain the same number of values as X. Each pair (x, y) is read in order.
Use sample (n-1) when your data is a subset of a larger population. Use population (n) when your data is the entire group.
CovarianceStrong positive correlation
13
Pearson correlation (r)0.9884
Mean of X6
Mean of Y8.6
Std dev of X3.1623
Std dev of Y4.1593
Variance of X10
Variance of Y17.3
Population covariance10.4
Sample covariance13
Pairs (n)5
Variance of X10
Variance of Y17.3
Covariance13

Sample covariance is 13.0000, indicating a positive relationship: as X increases, Y tends to increase. The Pearson r of 0.9884 places this on a scale of -1 to +1, making the strength easy to compare across different data sets.

  • Covariance reveals only the direction of a linear relationship. Its magnitude depends on the units of X and Y and cannot be compared across different data sets.
  • Sample covariance (n-1) is the right choice when your data is a subset of a larger population. It corrects the downward bias that would arise from dividing by n.
  • The Pearson correlation r standardizes covariance by the product of the two standard deviations, giving a unit-free value between -1 and +1 that measures the strength of the linear relationship.
  • The standard deviations are 3.1623 (X) and 4.1593 (Y), and the variances are 10 (X) and 17.3 (Y).

Next stepUse the Pearson r value to compare the strength of this relationship against other paired data sets, or feed the covariance into a portfolio risk calculation.

Pair-by-pair deviation table

Pairxᵢyᵢxᵢ - x̄yᵢ - ȳ(xᵢ - x̄)(yᵢ - ȳ)
123-4-5.622.4
247-2-1.63.2
3680-0.6-0
481122.44.8
5101445.421.6

x̄ = 6, ȳ = 8.6. Each row shows how far the pair sits from its mean and the contribution to covariance.

Formula

covpop=1Ni=1N(xixˉ)(yiyˉ)covsample=1N1(xixˉ)(yiyˉ)r=cov(x,y)σxσy\text{cov}_{\text{pop}} = \dfrac{1}{N}\sum_{i=1}^{N}(x_i-\bar{x})(y_i-\bar{y}) \qquad \text{cov}_{\text{sample}} = \dfrac{1}{N-1}\sum(x_i-\bar{x})(y_i-\bar{y}) \qquad r = \dfrac{\text{cov}(x,y)}{\sigma_x \sigma_y}

Worked example

For X = 2, 4, 6, 8, 10 and Y = 3, 7, 8, 11, 14: x̄ = 6, ȳ = 8.6. The deviation products sum to 52. Sample covariance = 52 / 4 = 13. StdX = 3.1623, StdY = 4.1593, Pearson r = 13 / (3.1623 x 4.1593) = 0.9884.

What covariance tells you

Covariance is a single number that captures whether two paired variables tend to move in the same direction or in opposite directions. For every pair the calculator multiplies how far X sits from its mean by how far Y sits from its mean. When both deviations share a sign the product is positive; when they differ the product is negative. Averaging those products gives the covariance. A positive value signals that above-average X tends to pair with above-average Y; a negative value signals the opposite. A value near zero means there is no consistent linear pattern connecting the two variables. The pair-by-pair deviation table below the result shows exactly how each data point contributes to the total.

Population versus sample covariance

The only difference between the two formulas is the divisor. Population covariance divides the summed deviation products by N, the full count of pairs, and is correct when your data covers every member of the group you care about. Sample covariance divides by N-1, applying Bessel's correction to remove the downward bias that appears when you estimate population behavior from a smaller sample drawn from it. Because dividing by a smaller number yields a larger result, the sample covariance is always slightly bigger in magnitude than the population covariance. When you are unsure whether you hold the whole population, statisticians default to the sample version with N-1. Both values are always shown in the results below for comparison.

Why covariance is hard to interpret alone, and how Pearson r fixes it

Covariance is sensitive to the units and scale of your data, which makes its raw magnitude difficult to compare across data sets. Measuring height in centimetres instead of metres multiplies the covariance by one hundred even though the underlying relationship is unchanged. That is why analysts convert covariance into the Pearson correlation coefficient r by dividing by the product of the two standard deviations. The result is always between -1 and +1, regardless of units. A value of +1 means a perfect positive linear relationship, -1 means a perfect negative one, and 0 means no linear relationship at all. Values above 0.7 or below -0.7 are conventionally described as strong; values between 0.3 and 0.7 as moderate; and values below 0.3 as weak.

Standard deviations, variances, and portfolio risk

Beyond the covariance, this calculator also reports the standard deviation and variance of each variable using the same population or sample denominator you chose. These are useful in their own right and are a prerequisite for several downstream calculations. In finance, for example, the variance of a two-asset portfolio is Var(X) x wX^2 + Var(Y) x wY^2 + 2 x wX x wY x cov(X, Y), where wX and wY are the portfolio weights. A negative or low covariance between two assets therefore reduces overall portfolio variance, which is the statistical basis for diversification. In machine learning, covariance matrices describe how features relate to one another in multivariate distributions and underpin techniques like PCA (principal component analysis).

Interpreting the Pearson correlation coefficient r

|r| rangeStrengthInterpretation
0.9 - 1.0 Very strong Near-perfect linear relationship
0.7 - 0.9 Strong Clear linear trend, low scatter
0.5 - 0.7 Moderate Noticeable trend, moderate scatter
0.3 - 0.5 Weak-moderate Some trend visible, high scatter
0.0 - 0.3 Weak/none Little to no discernible linear pattern

These conventional thresholds apply to absolute values of r. Negative values indicate an inverse relationship of the same strength.

Frequently asked questions

What is the difference between population and sample covariance?

Population covariance divides the sum of deviation products by N and is used when your data covers every member of the group. Sample covariance divides by N-1 (Bessel's correction) to give an unbiased estimate when your data is a sample drawn from a larger population, making it slightly larger in magnitude. Use the toggle at the top to switch between them; both values are always shown in the results for reference.

Can covariance be negative?

Yes. A negative covariance means the two variables tend to move in opposite directions: when one is above its mean, the other is usually below its mean. A positive covariance means they move together. A value near zero means there is no consistent linear relationship. The Pearson correlation r shown alongside the covariance places this on a -1 to +1 scale so the strength of the relationship is easy to read.

How is covariance related to the Pearson correlation coefficient?

The Pearson correlation r equals the covariance divided by the product of the two standard deviations: r = cov(X, Y) / (stdX x stdY). Covariance shows only the direction of a linear relationship and depends on units, whereas r also measures strength and is unit-free (always between -1 and +1), so it can be compared meaningfully across data sets. This calculator computes r for you alongside the covariance.

What do the standard deviation and variance outputs mean?

The variance is the average of the squared deviations from the mean (using the same n or n-1 denominator you chose). The standard deviation is the square root of the variance and is in the same units as your original data. Both are shown for X and Y separately. They are useful on their own and are the building blocks for computing r, portfolio risk, and many other statistics.

What does the pair-by-pair table show?

The deviation table below the result breaks the covariance calculation into individual rows: each row shows one (x, y) pair, how far each value sits from its mean (xi - x̄ and yi - ȳ), and the product of those two deviations. Summing that product column and dividing by n or n-1 gives the covariance. This makes it easy to spot which pairs contribute most to the overall result and to check the arithmetic manually.

How is covariance used in portfolio analysis?

In finance, the variance of a two-asset portfolio equals Var(X) x wX^2 + Var(Y) x wY^2 + 2 x wX x wY x cov(X, Y), where wX and wY are the weights of each asset. A low or negative covariance between two assets reduces the total portfolio variance, which is the statistical foundation for diversification. Plug the covariance and variances from this calculator directly into that formula.

Sources

Written by Dr. Hannah Brandt, PhD Statistician · Munich, Germany

Applied statistician translating rigorous probability theory into clear, accurate tools for researchers and practitioners.

Search 3,500+ calculators

Loading search…