What Is Degree of Freedom in a Chi-Square Test?

Degrees of freedom in a chi-square test represent the number of values in your data that are free to vary once you know the row and column totals. Think of it this way: if you have a table of numbers and you already know what each row and column must add up to, you can only fill in so many cells with whatever numbers you want before the remaining cells are locked in by simple arithmetic. That count of “free” cells is your degrees of freedom (often written as df).

This number matters because it determines which version of the chi-square distribution you use to judge whether your result is statistically significant. A chi-square value of 8 might be significant with 2 degrees of freedom but unremarkable with 10.

Why Degrees of Freedom Exist

Imagine you have a simple 2×2 table showing whether people in two groups got sick or stayed healthy. You know the total for each row and each column. Once you fill in just one cell freely, every other cell in that table is determined by subtraction. You have no choice about what goes there. That single free cell gives you 1 degree of freedom.

Now picture a larger table, say 3 rows and 3 columns. You can freely fill in four cells before the row and column totals force the remaining cells into place. That table has 4 degrees of freedom. The pattern holds regardless of table size: degrees of freedom tell you how much genuine, independent variation your data contains. A table with more categories carries more independent information, so it has more degrees of freedom.

The Formulas for Each Type of Test

Chi-square tests come in two main varieties, and each calculates degrees of freedom differently.

Test of Independence

This is the test you use when you have a contingency table (a grid crossing two categorical variables). The formula is:

df = (number of rows − 1) × (number of columns − 1)

A 2×2 table has (2−1) × (2−1) = 1 df. A 3×2 table has (3−1) × (2−1) = 2 df. A 4×5 table has (4−1) × (5−1) = 12 df. You subtract 1 from each dimension because knowing the marginal totals removes one free choice per row and per column.

Goodness-of-Fit Test

This test checks whether a single variable’s observed distribution matches an expected one (for example, whether dice rolls are evenly distributed across six outcomes). Here, there’s no grid of rows and columns, just a single row of categories:

df = number of categories − 1

If you’re testing outcomes across 4 groups, df = 4 − 1 = 3. If you’re testing 3 groups, df = 2.

A Worked Example

Suppose a company wants to know whether a pneumonia vaccine actually reduces illness. They split 184 employees into two groups of 92: one vaccinated, one not. At the end of winter, they record three outcomes (pneumococcal pneumonia, non-pneumococcal pneumonia, or no pneumonia) for each group, creating a 3×2 table.

The degrees of freedom are (3 − 1) × (2 − 1) = 2. That means two cells in the table carry independent information; the rest are determined by the row and column totals.

To run the test, you calculate expected values for each cell by multiplying that cell’s row total by its column total, then dividing by 184. For instance, the expected number of unvaccinated employees with pneumococcal pneumonia is (28 × 92) / 184 = 13.92. The observed count was 23, a notable gap. You then compute a chi-square value for each cell using (observed − expected)² / expected, and sum them all up. That total chi-square statistic, combined with 2 degrees of freedom, is what you look up in a chi-square table (or plug into software) to get a p-value.

How Degrees of Freedom Shape the Distribution

The chi-square distribution isn’t a single curve. It’s a family of curves, and each one corresponds to a specific number of degrees of freedom. With low df (like 1 or 2), the curve is heavily skewed to the right, piling most of its area near zero with a long tail stretching out. As df increases, the curve shifts rightward, spreads out, and becomes more symmetrical, though it never becomes perfectly symmetrical like a bell curve.

This shift is why the critical value for significance changes with degrees of freedom. At the standard 0.05 significance level, the critical value for 1 df is 3.841. For 5 df, it rises to 11.070. For 10 df, it’s 18.307. A higher degree of freedom means the test “expects” a larger chi-square statistic before flagging the result as significant, because there are more categories contributing variation.

What Happens With Small Tables

When your contingency table is a simple 2×2 (giving you just 1 degree of freedom), the chi-square approximation can be less accurate, especially with small sample sizes. The chi-square formula treats data as though it follows a smooth, continuous distribution, but your actual counts are whole numbers. With only 1 df, that gap between the smooth theoretical curve and your lumpy real data is most pronounced.

For 2×2 tables with small samples (typically fewer than 40 total observations), a correction called the Yates continuity correction is sometimes applied to compensate. It slightly reduces the chi-square value to avoid overstating significance. For tables larger than 2×2, larger chi-square values are needed to reach significance in the first place, so the correction is less of a concern. When sample sizes are very small regardless of table size, Fisher’s exact test is often a better alternative because it doesn’t rely on the chi-square approximation at all.

Quick Reference for Common Table Sizes

  • 2×2 table: 1 degree of freedom
  • 2×3 table: 2 degrees of freedom
  • 3×3 table: 4 degrees of freedom
  • 3×4 table: 6 degrees of freedom
  • 4×5 table: 12 degrees of freedom

For goodness-of-fit tests, just subtract 1 from the number of categories: 5 categories gives you 4 df, 6 categories gives you 5 df, and so on. In every case, the logic is the same. Degrees of freedom count the pieces of information in your data that are genuinely free to vary, and that count determines which chi-square distribution you use to evaluate your results.