Chi-Square CalculatorChi-Square Calculator
Guide

How to Calculate Chi-Square by Hand

The chi-square statistic takes five steps and nothing harder than division. Here they are on a small table, with every intermediate number shown so you can check your own working.

Checked on November 21, 2026. Results computed by our statistics engine, version 1.0.0.

In short

  • Five steps from counts to conclusion
  • A full (O − E)² / E table
  • A goodness-of-fit example too
On this page

The formula

χ² = Σ (O − E)² / E. For every cell, subtract the expected count E from the observed count O, square the difference, divide by E, and add up the results over all cells. The squaring makes every gap count positively, and dividing by E scales each gap by what was expected, so a gap of 5 matters more when 10 were expected than when 1,000 were.

The example table

This is the small example from SciPy's documentation for chi2_contingency (SciPy chi2_contingency): two groups and three categories, 100 observations in all.

Category ACategory BCategory C
Group 1101020
Group 2202020

Step 1: row, column and grand totals

Add each row and each column. Group 1 has 40 observations and group 2 has 60. The columns total 30, 30, 40. The grand total N is 100.

Step 2: expected counts

If the groups shared one distribution, each cell would get its row's share of its column: E = row total × column total / N. For group 1, category A that is 40 × 30 / 100 = 12.00. Check that the expected counts in each row and column add to the same totals as the observed counts.

Step 3: (O − E)² / E for every cell

CellOEO − E(O − E)² / E
Group 1, Category A1040 × 30 / 100 = 12.00−2.000.3333
Group 1, Category B1040 × 30 / 100 = 12.00−2.000.3333
Group 1, Category C2040 × 40 / 100 = 16.004.001.0000
Group 2, Category A2060 × 30 / 100 = 18.002.000.2222
Group 2, Category B2060 × 30 / 100 = 18.002.000.2222
Group 2, Category C2060 × 40 / 100 = 24.00−4.000.6667

Add the last column: χ² = 0.3333 + 0.3333 + 1.0000 + 0.2222 + 0.2222 + 0.6667 = 2.7778. Keep at least four decimals in the intermediate steps; rounding each cell to one decimal can shift the total enough to matter near a cutoff.

Step 4: degrees of freedom

For a table, df = (rows − 1) × (columns − 1) = (2 − 1) × (3 − 1) = 2. The idea: once the totals are fixed, only 2 cells can be filled freely; the rest follow. For goodness of fit, df = categories − 1.

Step 5: compare and conclude

In the chi-square table, the critical value for 2 degrees of freedom at α = 0.05 is 5.991. Our χ² of 2.778 is smaller, so the result is not significant at the 5% level. The exact p-value, from the p-value calculator, is 0.2494.

Word the conclusion in terms of the question, not the arithmetic: "There is no evidence, at the 5% level, that the distribution across categories differs between the two groups." Avoid "the groups are the same"; a non-significant test does not show that. SciPy's documentation prints the same statistic and p-value.

A goodness-of-fit example by hand

OpenStax gives the number of absences on each weekday, 15, 12, 9, 9, 15 (OpenStax 11.2), and asks whether absences are spread evenly. The total is 60, so each expected count is 60 / 5 = 12.

DayOE(O − E)² / E
Monday15120.7500
Tuesday12120.0000
Wednesday9120.7500
Thursday9120.7500
Friday15120.7500

χ² = 3.0000 with 4 degrees of freedom, p = 0.5578. No evidence that absences differ by weekday.

Checks before you trust the answer

  • Every expected count should be at least 5, or at least meet Cochran's rule. Here the smallest is 12.00. See the expected counts guide.
  • Use counts, never percentages.
  • For a 2x2 table, decide in advance whether to use the Yates correction, and say so. See the Yates guide.
  • Check your arithmetic with the chi-square calculator; it shows the same contributions in its "Category by category" and expected-count panels.

Sources