Covariance measures whether two variables tend to move together, move in opposite directions, or show no consistent linear relationship at all. It's the building block behind correlation, regression, and portfolio variance in finance — this calculator walks through the population and sample versions side by side, plus how covariance standardizes into the more familiar Pearson correlation coefficient.

How covariance works

Covariance sums the product of each point's deviation from the X mean and the Y mean: Σ(xᵢ − x̄)(yᵢ − ȳ). When a point's X is above average at the same time its Y is above average (or both below average), that product is positive — pulling the sum, and the covariance, upward. When one is above average while the other is below, the product is negative — pulling the sum down. A covariance near zero means these positive and negative products roughly cancel out, indicating no consistent linear tendency.

Population vs. sample — why the divisor changes

Population covariance divides the sum of deviation products by N, the full count — appropriate when your data already is the entire group you care about. Sample covariance divides by n − 1 instead. This adjustment, known as Bessel's correction, exists because a sample's own mean is calculated from the same data used to measure the deviations, which slightly understates the true variability relative to the larger population the sample was drawn from. Dividing by a smaller number (n − 1 instead of n) inflates the estimate just enough to correct for that bias, making the sample statistic an unbiased estimator of the population covariance.

Relationship to correlation

Covariance's biggest limitation is that its magnitude depends on the units and scale of X and Y — a covariance of 1,000 could reflect a weak relationship between large-scale variables or a strong relationship between small-scale ones, and there's no way to tell which just by looking at the number. Pearson correlation solves this by dividing covariance by the product of the two variables' standard deviations, r = Cov(X,Y) / (σx · σy), which rescales the result to always fall between −1 and +1 regardless of the original units. This is why correlation is usually the more useful number for comparing relationships across different datasets, while covariance remains foundational in contexts — like portfolio variance calculations — where the actual scale of the variables matters.