StatGardenREF. DESK
Calculators/Statistics/Covariance
Statistics

Covariance calculator

How two variables move together, in sample or population form.

Published 6 August 2026 · Updated 25 September 2026

What this calculator does

Covariance measures whether two variables move together. It is positive when above-average values of one tend to accompany above-average values of the other, and negative when they move oppositely.

Its weakness is that the size is uninterpretable. A covariance of 13.5 says the relationship is positive but nothing about how strong, because the number carries the units of both variables multiplied together. Dividing by the two standard deviations fixes this and gives the correlation coefficient, which for the same data is 0.9718 and immediately means something.

The formula

FormulaSample: Σ(xᵢ−x̄)(yᵢ−ȳ)/(n−1); Population: Σ(xᵢ−x̄)(yᵢ−ȳ)/n

Each pair of deviations from the two means is multiplied and the products are summed. The sample version divides by n−1 and the population version by n. Both are reported alongside the correlation coefficient, which standardises the covariance by the product of the standard deviations to give a value between −1 and 1.

TermMeaning
CovarianceThe average product of paired deviations from the two means.
CorrelationCovariance divided by the two standard deviations, giving a scale-free value from −1 to 1.
Sample vs populationThe n−1 or n divisor, which changes the covariance but not the correlation.
SignPositive means the variables move together, negative means oppositely.

The inputs explained

FieldWhat to enter
X valuesX values, comma or space separated.
Y valuesY values, in the same order and the same count as X.
TypeSample for data drawn from a larger population, which is the usual case.

When to use it

Checking whether two measures relate

The sign of the covariance answers the direction question immediately, even if the magnitude does not help.

Building a portfolio

Covariance between asset returns is the input to portfolio variance, and is used directly rather than standardised.

Preparing for regression

The slope of a simple linear regression is the covariance divided by the variance of X.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

What does covariance look like for different relationships?

Positive, negative and weak relationships compared.

Three pairs of variables
Y values (X = 1, 2, 3, 4, 5)CovarianceDirectionCorrelation r (standardised covariance)
10, 8, 6, 4, 2-5.000Negative: tend to move oppositely-1.000
3, 1, 4, 1, 51.000Positive: tend to move together0.3536
2, 4, 6, 8, 105.000Positive: tend to move together1.000
The first and last rows are both perfectly linear, giving correlations of exactly −1 and 1, but their covariances of −5 and 5 tell you nothing about that perfection on their own. The middle row has a covariance of 1 and a correlation of only 0.3536, which is the figure that actually describes the relationship.

Questions

What is the difference between covariance and correlation?

Correlation is covariance divided by the product of the two standard deviations. That division removes the units and confines the result to between −1 and 1, making it comparable across data sets. Covariance keeps the units and so cannot be judged without knowing the scales involved.

Does the sample or population version matter?

It changes the covariance, from 13.5 to 10.8 on this calculator default data, but not the correlation, which is 0.9718 either way. The divisor cancels when standardising. Use the sample version unless your data genuinely is the entire population.

Can covariance be zero when the variables are related?

Yes. Covariance detects only linear association. Variables related by a symmetric curve, such as y = x² over a range centred on zero, can have exactly zero covariance while being perfectly determined by each other. Zero covariance means no linear relationship, not independence.

What is a large covariance?

There is no answer without knowing the scales, which is the fundamental limitation. Measuring the same relationship in metres rather than centimetres changes the covariance by a factor of 10,000. If you want a magnitude you can interpret, use the correlation.

For the standardised version, see the correlation coefficient calculator. For a rank-based alternative, see the Spearman’s rank correlation calculator.