Covariance Calculator

Paste two lists of paired values. The calculator returns the sample covariance (÷(n − 1)), the population covariance (÷n), Pearson’s r, both standard deviations and a scatter plot with the fitted line.

Separate values with commas, spaces or semicolons.
The same number of y values as x values, in the same order (paired).
SAMPLE COVARIANCE
59.2500
Positive covariance: x and y tend to move together. Pearson’s r = 0.9959, a very strong positive linear relationship.
SAMPLE COVARIANCE
59.2500
POPULATION COVARIANCE
47.4000
PEARSON r
0.9959
SD OF x
4.7434
SD OF y
12.5419
PAIRS (n)
5
Check: Cov = r × SDx × SDy = 0.9959 × 4.7434 × 12.5419 = 59.2500.

Worked steps

    Watch the units. Covariance is measured in the units of x times the units of y, so its size alone cannot be compared across datasets. That is why the calculator also shows Pearson’s r — the standardised version of covariance, always between −1 and 1.

    Enter up to four variables. The calculator returns the full symmetric sample covariance matrix, plus each variable’s mean and sample standard deviation.

    COVARIANCE MATRIX (SAMPLE)
    3 × 3 matrix
    The matrix is symmetric: the entry in row i, column j equals the entry in row j, column i. The diagonal holds each variable’s sample variance.

    Worked steps

      Reading the matrix. The diagonal is each variable’s variance (the covariance of a variable with itself). Off the diagonal, a positive entry means the two variables move together; a negative entry means they move in opposite directions.

      The covariance calculator works out sample and population covariance for paired data, shows the correlation alongside, and plots the scatter. A covariance-matrix mode handles three or four variables at once. Covariance measures direction and strength in the units of your data, so the page explains why its size alone is not comparable.

      What is covariance?

      Covariance measures how two variables move together. For each pair, it multiplies how far x is from its mean by how far y is from its mean, then averages those products. When x is above its mean at the same time y is above its mean, the product is positive; when one is above and the other below, the product is negative.

      The sign is the headline: a positive covariance means the variables tend to rise together, a negative covariance means one tends to fall as the other rises, and a covariance near zero means there is no linear pattern between them. Covariance does not prove that one variable causes the other — it only describes the linear association in the data you have.

      Covariance is the building block of two familiar quantities. Divide it by the two standard deviations and you get Pearson’s correlation coefficient r; divide it by the variance of x and you get the slope of the least-squares regression line. That is why covariance matters even though you will rarely quote it on its own.

      How to use the covariance calculator

      Paired covariance. Paste your x values in the first box and your y values in the second, in the same order. The calculator returns the sample covariance, the population covariance, Pearson’s r, both standard deviations, a pair-by-pair deviation table and a scatter plot with the fitted line. Try it now with x = 12, 15, 18, 21, 24 and y = 30, 38, 44, 55, 61: the sample covariance is 59.2500 and r is 0.9959.

      Covariance matrix. Choose 2, 3 or 4 variables, name each one and paste its values. The calculator returns the full symmetric sample covariance matrix, plus each variable’s mean and sample standard deviation. Try it now with study_hrs = 5, 6, 7, 8, 9, 4, sleep_hrs = 7, 6, 8, 7, 9, 6 and score = 80, 85, 88, 92, 95, 78: the matrix is [[3.5000, 1.7000, 12.4000], [1.7000, 1.3667, 5.7333], [12.4000, 5.7333, 44.2667]].

      The formula — sample vs population

      For paired data (x₁, y₁), …, (xₙ, yₙ) with means x̄ and ȳ, the sample covariance is:

      Cov(x, y) = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1)

      The population covariance uses the same numerator but divides by n instead of n − 1:

      Covpop(x, y) = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ n

      Use the sample version when your data are a sample drawn from a larger population (the usual case, and the default on this page). Use the population version only when your data are the entire population you care about. The two differ by a factor of n/(n − 1), so they are close when n is large and noticeably different when n is small.

      The identity to remember: Cov = r × SDx × SDy. Covariance is the correlation multiplied by the two standard deviations. That single line explains both the units problem (below) and why r is the comparable number.

      The regression link is just as direct: the slope of the least-squares line of y on x is slope = Cov(x, y) ÷ Var(x). If the covariance is positive the line slopes up; if it is negative the line slopes down. See the linear regression calculator to fit that line.

      Worked examples

      Example 1 — paired covariance

      x = [12, 15, 18, 21, 24], y = [30, 38, 44, 55, 61]. The means are x̄ = 18.0000 and ȳ = 45.6000. The deviations multiply out to 93.6000, 22.8000, 0.0000, 28.2000 and 92.4000, which sum to 237.0000. The sample covariance is 237.0000 ÷ 4 = 59.2500; the population covariance is 237.0000 ÷ 5 = 47.4000. The sample standard deviations are SDx = 4.7434 and SDy = 12.5419, so Pearson’s r = 59.2500 ÷ (4.7434 × 12.5419) = 0.9959. The check: 0.9959 × 4.7434 × 12.5419 = 59.2500.

      Example 2 — covariance matrix

      Three variables measured on six students: study_hrs = [5, 6, 7, 8, 9, 4], sleep_hrs = [7, 6, 8, 7, 9, 6], score = [80, 85, 88, 92, 95, 78]. The sample covariance matrix is:

      study_hrssleep_hrsscore
      study_hrs3.50001.700012.4000
      sleep_hrs1.70001.36675.7333
      score12.40005.733344.2667

      The diagonal holds the variances: study_hrs 3.5000, sleep_hrs 1.3667, score 44.2667. Off the diagonal, study time and score move together most strongly (12.4000), and sleep and score move together too (5.7333). All three pairs are positive, so in this small dataset more study and more sleep both go with higher scores.

      Why you cannot compare two covariances

      Covariance carries the units of x multiplied by the units of y. If x is measured in hours and y in points, the covariance is in “hour-points” — a unit with no meaning outside that dataset. Change the units (hours to minutes, points to a percentage) and the covariance changes by a large factor even though the relationship is identical. That is the units problem, and it is why a covariance of 59.25 in one dataset and 0.42 in another tells you nothing about which relationship is stronger.

      That is exactly why we standardise covariance into Pearson’s r. Dividing by the two standard deviations strips the units away and leaves a number between −1 and 1 that can be compared across any two datasets. Use covariance when you need the raw joint spread (for a regression slope, or for a covariance matrix); use r when you want to compare strength.

      The rule: compare r, not covariance. A covariance of 12.4 and a covariance of 0.8 can describe the same strength of relationship if their standard deviations differ — r is the number that puts them on the same scale.

      The regression connection makes the units concrete. The slope of y on x is Cov(x, y) ÷ Var(x), so the slope inherits the units “y per x”. In Example 1, the slope is 59.2500 ÷ 22.5000 = 2.6333 points of y per unit of x. See the linear regression calculator to fit that line, and the standard deviation calculator for the spread behind it.

      Covariance vs correlation

      CovarianceCorrelation (r)
      What it measuresDirection and joint spread of x and yDirection and strength of the linear relationship
      RangeAny real number (−∞ to +∞)Always between −1 and 1
      UnitsUnits of x × units of yNone (unit-free)
      Comparable across datasets?No — the size depends on the unitsYes — that is its purpose
      Use it whenYou need a regression slope or a covariance matrixYou want to compare strength or report the relationship

      The two are the same idea at different scales: r is covariance divided by the two standard deviations. The correlation coefficient calculator puts r first, with interpretation and a scatter plot; this page puts covariance first, with r alongside.

      Check: the calculator against the test matrix

      Run this row through the paired mode and confirm the numbers match: x = [2, 4, 6, 8, 10], y = [9, 7, 5, 4, 2]. The means are x̄ = 6.0000 and ȳ = 5.4000; the cross-products sum to −34.0000. The sample covariance is −34.0000 ÷ 4 = −8.5000, the population covariance is −34.0000 ÷ 5 = −6.8000, and Pearson’s r = −0.9948. A strong negative relationship: as x rises, y falls.

      Frequently asked questions

      What does covariance tell you?

      Covariance tells you the direction of the linear relationship between two variables, and how much they vary together. A positive value means they tend to rise together; a negative value means one tends to fall as the other rises; zero means no linear pattern. Its size also reflects the spread of the data, so it is not a pure measure of strength — that is what the correlation is for.

      Why can’t you compare two covariances directly?

      Because covariance carries the units of x times the units of y. Two datasets in different units (or with different spreads) will have covariances on completely different scales even when the underlying relationship is identical. Standardise it — divide by the two standard deviations — and you get Pearson’s r, which is unit-free and comparable.

      What is the difference between sample and population covariance?

      The sample covariance divides the sum of cross-products by n − 1; the population covariance divides by n. Use the sample version when your data are a sample from a larger population (the usual case); use the population version only when your data are the whole population. The sample value is always slightly larger in magnitude.

      How is covariance related to correlation?

      Correlation is covariance standardised: r = Cov ÷ (SDx × SDy). Equivalently, Cov = r × SDx × SDy. The correlation is always between −1 and 1; covariance has no fixed range. They always have the same sign, and r = 0 exactly when the covariance is 0.

      Source: the sample covariance is the standard textbook definition, Cov(x, y) = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1), with the population version dividing by n. The identity Cov = r × SDx × SDy and the regression slope Cov ÷ Var(x) follow directly from that definition.