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 A | Category B | Category C | |
|---|---|---|---|
| Group 1 | 10 | 10 | 20 |
| Group 2 | 20 | 20 | 20 |
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
| Cell | O | E | O − E | (O − E)² / E |
|---|---|---|---|---|
| Group 1, Category A | 10 | 40 × 30 / 100 = 12.00 | −2.00 | 0.3333 |
| Group 1, Category B | 10 | 40 × 30 / 100 = 12.00 | −2.00 | 0.3333 |
| Group 1, Category C | 20 | 40 × 40 / 100 = 16.00 | 4.00 | 1.0000 |
| Group 2, Category A | 20 | 60 × 30 / 100 = 18.00 | 2.00 | 0.2222 |
| Group 2, Category B | 20 | 60 × 30 / 100 = 18.00 | 2.00 | 0.2222 |
| Group 2, Category C | 20 | 60 × 40 / 100 = 24.00 | −4.00 | 0.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.
| Day | O | E | (O − E)² / E |
|---|---|---|---|
| Monday | 15 | 12 | 0.7500 |
| Tuesday | 12 | 12 | 0.0000 |
| Wednesday | 9 | 12 | 0.7500 |
| Thursday | 9 | 12 | 0.7500 |
| Friday | 15 | 12 | 0.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
- SciPy documentation: scipy.stats.chi2_contingency checked November 21, 2026
- OpenStax, Introductory Statistics 2e, section 11.2: goodness-of-fit test checked November 21, 2026