ProMathTools
ProMathTools

Covariance Calculator

Calculate sample covariance between two datasets ? aligned with the standard ProMathTools calculator layout.

Commas, spaces, or semicolons between values

Commas, spaces, or semicolons between values

How the covariance calculator works

Covariance measures how two variables move together. When values of X that are above their average tend to pair with values of Y that are above their average, the covariance is positive. When high X values pair with low Y values, it is negative, and when there is no consistent linear pattern it sits near zero. This calculator returns the sample covariance, which divides by n ? 1 and is the standard choice when your data is a sample drawn from a larger population. It is a building block for correlation, linear regression, portfolio risk in finance, and principal component analysis.

Required Inputs & Typical Use Cases

  • Dataset X

    The first list of numbers. Separate values with commas, spaces, or semicolons.

  • Dataset Y

    The second list, paired with X by position. It must contain exactly as many values as X, and at least two.


The Formula

x? = ?x? / n        ? = ?y? / n
cov(X, Y) = ?[(x? ? x?)(y? ? ?)] / (n ? 1)      (sample)
cov(X, Y) = ?[(x? ? x?)(y? ? ?)] / n            (population)
  • x?, y?

    The i-th paired observations from the two datasets.

  • x?, ?

    The arithmetic means of X and Y.

  • n

    The number of pairs. Sample covariance divides by n ? 1 to correct bias.


Worked Example

  1. Example 1: X = 1, 2, 3 and Y = 2, 3, 5

    Means: x? = (1 + 2 + 3) / 3 = 2 and ? = (2 + 3 + 5) / 3 ? 3.3333. Deviation products: (1 ? 2)(2 ? 3.3333) = 1.3333, (2 ? 2)(3 ? 3.3333) = 0, (3 ? 2)(5 ? 3.3333) = 1.6667. Sum = 3. Sample covariance = 3 / (3 ? 1) = 1.5. The positive sign says Y tends to rise as X rises.

  2. Example 2: X = 1, 2, 3, 4 and Y = 8, 6, 5, 1

    Means: x? = 2.5 and ? = 5. Products: (?1.5)(3) = ?4.5, (?0.5)(1) = ?0.5, (0.5)(0) = 0, (1.5)(?4) = ?6. Sum = ?11. Sample covariance = ?11 / 3 ? ?3.6667. The negative sign shows the variables move in opposite directions.


Tips, Assumptions & Limitations

  • Common mistake: unequal list lengths. Every X value needs a matching Y value in the same position, so the two datasets must have the same count.
  • Common mistake: mixing up sample and population formulas. This tool divides by n ? 1. If your data is the entire population, divide the same sum by n instead; Example 1 would then give 1 rather than 1.5.
  • Common mistake: reading the size as strength. Covariance depends on the units of X and Y, so a value of 50 is not automatically strong. Use the correlation coefficient to get a unitless score between ?1 and 1.
  • Covariance only captures linear association. Two variables can be strongly related in a curve and still show a covariance near zero.
  • Outliers can swing the result sharply because deviations are multiplied together, so check your data for entry errors first.
  • The covariance of a variable with itself is its variance, which you can confirm with the variance calculator.
FAQ

Covariance measures the linear relationship between two datasets. A positive value means the variables tend to rise together, a negative value means one tends to fall as the other rises, and a value near zero suggests no linear pattern.

Sample covariance is the sum of (xi minus the mean of x) times (yi minus the mean of y), divided by n minus 1. For population data, divide by n instead.

It uses the sample formula and divides by n - 1, which is the right choice when your data is a sample of a larger group. To get the population value, multiply the result by (n - 1) / n.

Covariance is measured in the product of the two variables' units, so its size is hard to interpret. Correlation divides covariance by both standard deviations, producing a unitless number between -1 and 1 that shows the strength of the relationship.

Yes. Negative covariance means the variables move in opposite directions. A covariance of zero means there is no linear relationship, although a non-linear relationship could still exist.

Type the numbers for X and Y in the two boxes, separated by commas, spaces, semicolons, or new lines. Both lists must have the same number of values, with at least two in each.

Companion article

Covariance Calculator: Understanding the Concept

Related Calculators

Correlation CoefficientLinear RegressionStandard DeviationVariance CalculatorMean CalculatorZ-Score CalculatorSample Size CalculatorT-Test CalculatorConfidence IntervalMedian ModeNormal Distribution

Related Guides


How this calculator works

Covariance measures the linear relationship between two datasets

Explanation

The formula for covariance is cov(X, Y) = Σ[(xi - x̄)(yi - ȳ)] / (n - 1)

Formula

cov(X, Y) = Σ[(xi - x̄)(yi - ȳ)] / (n - 1)

Worked example

Calculate the covariance between two datasets: X = [1, 2, 3], Y = [2, 3, 5]

How to use this tool

Enter the datasets in the input fields and click calculate to get the covariance

Frequently asked questions

What is covariance?
Covariance measures the linear relationship between two datasets

Read the full guide →

About UsBlogChrome ExtensionFAQsTerms and ConditionsPrivacy PolicySitemap
EmailLinkedInFacebook

© 2025-2026 PromathTools. All rights reserved.

Built by KruskalCode – SaaS & Automation Experts · EverydayDevTools