Covariance Calculator - Sample, Population, and r

Covariance calculator that returns sample covariance, population covariance, variances, means, sample size, and Pearson r for paired data.

Updated: June 20, 2026 • Free Tool

Covariance Calculator

Enter the first paired sample. Numbers, decimals, negatives, and duplicates are all accepted.

The second paired sample. Each value should pair with the value at the same position in Dataset X.

Sample covariance uses n - 1 in the denominator (default for a sample of observations). Population covariance uses n (for the full population).

Results

Sample Covariance
0
Population Covariance 0
Pearson r (for reference) 0
Variance of X (sample) 0
Variance of Y (sample) 0
Mean of X 0
Mean of Y 0
Sample Size (n) 0
Direction 0

What Is a Covariance Calculator?

A covariance calculator turns two paired columns of numbers into a single signed value that describes how much the variables move together. This covariance calculator returns both the sample and the population form, the variance of each column, the column means, and the Pearson r, so the result sits naturally alongside the rest of your descriptive statistics.

  • Coursework and lab reports: Quantify how strongly two measurements move together for a stats class, AP Statistics, or psychology methods lab without building a spreadsheet.
  • Survey and Likert data: Pair pre-survey and post-survey scores, or stress and sleep ratings, to see whether higher stress tends to come with worse sleep.
  • Finance and portfolio work: Compute the covariance of two stock or asset return series to feed a portfolio variance or modern portfolio theory calculation.
  • Pre-analysis for correlation and regression: Run covariance first, then check Pearson r and standard deviations on the same screen to understand what drives the relationship.

Covariance is signed, so a positive value means the two variables tend to rise together, while a negative value means one rises as the other falls. The magnitude depends on the units of both variables, which is why the calculator always reports Pearson r alongside the raw covariance.

For a unit-free strength score built from the same paired data, the Correlation Calculator returns Pearson r, Spearman rho, or Kendall tau with a p-value and an interpretation band.

How This Covariance Calculator Works

The calculator parses the two datasets into matched pairs, then computes the cross-product sum of deviations in a single pass through the data. The computational formula uses raw sums and avoids subtracting the mean from every observation, which keeps the calculation numerically stable on small datasets.

cov(X, Y) = (Σxy − (Σx · Σy)/n) / (n − 1) (sample) · cov(X, Y) = (Σxy − (Σx · Σy)/n) / n (population)
  • n: Number of complete pairs after parsing.
  • Σx, Σy: Sum of the X and Y values.
  • Σxy: Sum of the product of each matched pair.
  • n − 1 vs n: Sample covariance divides by n − 1 (Bessel's correction); population covariance divides by n.

Once the cross-deviation sum is known, the calculator divides by n − 1 for sample covariance or n for population covariance. It also derives sample variances of X and Y with the same denominator, then divides the sample covariance by the product of the standard deviations to give Pearson r as a dimensionless companion.

Worked example: 10 paired values from NIST

Dataset X: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; Dataset Y: 2, 4, 5, 4, 5, 7, 8, 9, 10, 11; Mode: sample.

n = 10, Σx = 55, Σy = 65, Σxy = 436, Σx² = 385, Σy² = 501. Cross-deviation sum = Σxy − (Σx·Σy)/n = 436 − 357.5 = 78.5.

Sample covariance = 78.5 / 9 ≈ 8.7222, and population covariance = 78.5 / 10 = 7.85.

A positive covariance matching a Pearson r of about 0.9755, which the calculator reports in the same row.

According to NIST/SEMATECH e-Handbook of Statistical Methods, the computational formula for sample covariance is cov(X, Y) = (Σxy − (Σx·Σy)/n) / (n − 1) and the population form divides by n instead of n − 1.

The Pearson r reported alongside the covariance is built from the column standard deviations, and the Standard Deviation Calculator reproduces either standard deviation in isolation for spot-checking.

Key Concepts Explained

Four ideas show up every time someone interprets a covariance. Knowing them prevents the two most common mistakes: comparing covariances across different units and assuming a large magnitude implies a strong relationship.

Sample vs population covariance

Sample covariance divides by n − 1 (Bessel's correction) and is what descriptive-statistics packages return by default. Population covariance divides by n and is the right form only when the data really is the whole population, not a sample drawn from it.

Signed direction

A positive covariance means the two variables tend to rise together, a negative covariance means they tend to move in opposite directions, and a covariance near zero means there is no linear trend between them. The sign is meaningful even when the magnitude is hard to interpret.

Units and scale

Covariance carries the product of the units of X and Y (for example, kg·cm if X is in kilograms and Y is in centimetres). Changing the unit of either variable changes the covariance, which is why you should compare Pearson r across studies instead of raw covariance.

Relation to Pearson r

Pearson r is covariance divided by the product of the two standard deviations, which makes it unit-free and bounded between −1 and +1. The calculator reports both so you can read the direction from the covariance and the strength from r.

For a wider descriptive summary that includes mean, median, and spread before checking association, the Statistics Calculator gives the same kind of read on a single dataset.

How to Use This Covariance Calculator

Enter the two samples, choose sample or population mode, and read off the result. The calculator updates as you type.

  1. 1 Collect paired observations: Make sure each X value has a matching Y value at the same position. Different lengths trigger a validation error.
  2. 2 Paste the values into X and Y: Use commas, spaces, tabs, or newlines as separators. Decimals, negatives, and repeated values are all accepted.
  3. 3 Pick sample or population mode: Use sample mode for a sample drawn from a larger population; use population mode only when the data really is the whole population.
  4. 4 Read the primary covariance: The result panel shows the chosen mode's covariance at the top, the alternative mode underneath, variances, means, and Pearson r for context.
  5. 5 Interpret the direction label: Positive covariance with a moderate-to-strong r means the variables rise together; a negative value with the same r means they move in opposite directions.
  6. 6 Compare with the standard deviation check: Run standard deviation on each column if you want to verify the r result by hand, since r = cov / (sigma_x · sigma_y).

A student wants to know how strongly study hours and exam score move together for 10 students. They paste the 10 paired observations, leave the mode on sample, and read sample covariance = 8.72, sample variance of hours = 9.17, sample variance of score = 8.54, and Pearson r = 0.9755. The direction label reads 'very strong positive relationship', so they quote r in the write-up rather than the raw covariance, since r is unit-free.

When the covariance is clearly non-zero, the natural next step is fitting the line itself, and the Linear Regression Calculator takes the same X and Y inputs and returns slope and intercept.

Benefits of Using This Covariance Calculator

A covariance calculator removes the manual spreadsheet work and gives you both the sample and population forms, the column variances and means, and Pearson r in a single screen.

  • Sample and population in one tool: Switch between the n − 1 and the n denominator without re-entering data, so you can see how Bessel's correction changes the answer for small samples.
  • Pearson r alongside raw covariance: You get the unit-free correlation in the same row, which is what most reporting templates and lab rubrics actually expect.
  • Variances and means included: The variances and column means let you reproduce the result by hand or feed it into a portfolio variance, MANOVA, or factor analysis step.
  • Handles real-world data quirks: Ties, decimals, negatives, and uneven spacing in pasted lists are all accepted. The parser strips stray tokens and reports the count.
  • Plain-language direction label: The direction card translates the sign of the covariance and the magnitude of r into a single sentence so non-statisticians can read the result.
  • Pairs with the rest of your analysis: Use it as a front end for a correlation check, a regression run, or a t-test, all of which already live on this site.

Because r is covariance divided by the product of the standard deviations, checking a few standardised values with the Z-Score Calculator is a quick way to verify the r you see in the results panel.

Factors That Affect Your Results

Five things drive the size, sign, and interpretability of a covariance. Knowing them up front prevents the two recurring traps: comparing covariances across units and treating a near-zero r as proof of independence.

Choice of denominator

Sample covariance divides by n − 1 and is unbiased for the population value; population covariance divides by n and is only correct when the data really is the full population. With small samples the two forms can differ by 10 percent or more.

Units of measurement

Doubling the unit of X doubles the covariance. This is the reason Pearson r, which divides by the standard deviations, is the standard way to compare two relationships across studies that use different scales.

Sample size

Small samples make the covariance volatile: a single extreme pair can swing the sign or the magnitude. With fewer than 10 pairs, treat any near-zero result as inconclusive and report the sample size alongside the value.

Outliers and skew

A single outlying pair contributes a large cross product to the numerator and can dominate the result. With skewed or heavy-tailed data, consider a rank-based measure such as Spearman rho as a robustness check.

Linearity of the relationship

Covariance and Pearson r both measure linear association. A perfectly quadratic but tight relationship can produce a covariance near zero, so always plot the data before quoting the number.

  • Covariance is not standardised: a larger absolute value does not always mean a stronger relationship, because the units of X and Y are folded in.
  • Like any sample statistic, the covariance is an estimate; with small n the confidence interval around it is wide, so report n alongside the value.
  • Near-zero covariance does not prove the variables are independent; they could still be linked through a non-linear or rank-based pattern that covariance cannot see.

According to Wikipedia, Covariance, sample covariance of X and Y is the sum of products of deviations divided by n − 1, and the result has units equal to the product of the units of X and Y, unlike the dimensionless correlation coefficient.

For paired samples where you also want to test whether the mean difference is non-zero, the T-Test Calculator runs the matched-pairs t-test that uses this covariance in its denominator.

Covariance calculator returning sample covariance, population covariance, Pearson r, variances, and means for paired data
Covariance calculator returning sample covariance, population covariance, Pearson r, variances, and means for paired data

Frequently Asked Questions

Q: What does a covariance calculator actually compute?

A: It takes two paired lists of numbers and returns the cross-product sum of deviations, divided by n - 1 for a sample or n for a full population. The calculator also reports the variances, the column means, and Pearson r so the result is usable for homework, lab reports, or a quick portfolio variance check.

Q: How is sample covariance different from population covariance?

A: Sample covariance divides the cross-product sum by n - 1 and is the default in most statistics packages. Population covariance divides by n and is the right form only when the data really is the full population, not a sample drawn from it.

Q: What is the difference between covariance and correlation?

A: Covariance has units equal to the product of the units of X and Y, so its magnitude depends on the scale. Pearson correlation divides covariance by the product of the standard deviations, so it is unit-free and bounded between -1 and +1. Use correlation when you want to compare strength across studies.

Q: What does a positive or negative covariance mean?

A: Positive covariance means the two variables tend to rise together: when X is above its mean, Y is also above its mean on average. Negative covariance means they tend to move in opposite directions. A covariance near zero means there is no clear linear trend.

Q: Can the covariance calculator return zero for paired data?

A: Yes. A covariance of exactly zero is returned when one of the columns has no variation, or when the positive and negative cross products cancel. Zero covariance means no linear trend, not necessarily independence, so it is worth checking a scatter plot before concluding.

Q: What are common uses of covariance in real work?

A: Covariance shows up in portfolio variance and modern portfolio theory, in linear regression slope formulas, in principal component analysis, in time-series analysis, and in any descriptive-statistics workflow that pairs two measurements on the same units.