Chi-Square Test Explained
A chi-square test turns a table of counts into a single number that says whether the pattern in the table is real — or just chance.
The chi-square test is the go-to test for categorical data: counts in categories, not measurements. Give it a table of observed counts — how many people preferred each option, how many dice rolls landed on each face — and it compares those counts with the counts you would expect if nothing were going on. If the gap is too big to be chance, the test says so. This guide works through three examples on the site’s own numbers, including the Yates correction and Cramér’s V, and shows you exactly when the test should not be used.
A chi-square test compares observed counts with the counts expected if nothing were going on: χ² = Σ(O − E)²/E. A large value means the pattern is unlikely to be chance, and the test is used for goodness of fit and for independence.

What Is a Chi-Square Test?
A chi-square test is a hypothesis test for categorical data. Instead of measuring things on a scale — heights, times, temperatures — it counts how many observations fall into each category: how many voters chose each candidate, how many products came off each line, how many dice rolls landed on each face. The test then asks a simple question: do these counts look like what you would expect if nothing interesting were happening?
The “nothing interesting” baseline is the null hypothesis. For a goodness-of-fit test it is a claimed pattern — a fair die should give each face one sixth of the rolls. For a test of independence it is the claim that the two variables in the table have nothing to do with each other — the choice a person makes does not depend on the group they belong to. The test turns the gap between the observed counts and the expected counts into one number, χ², and then asks how surprising that number is.
Because the test works on counts, it needs no assumption that the data is bell-shaped. That is what makes it different from the z-tests and t-tests you may already know: those compare means, while chi-square compares whole tables of counts. Run the numbers on your own table with the chi-square test calculator — it gives χ², the p-value, the Yates correction and Cramér’s V in one go.
The Formula: χ² = Σ(O − E)²/E
The chi-square statistic is built cell by cell:
χ² = Σ (O − E)² / E, summed over every cell in the table. O is the observed count in a cell, E is the expected count in that cell.
Each part of the formula does a job. Subtracting E from O measures the gap in that cell. Squaring the gap does two things: it stops a cell that is above expectation from cancelling a cell that is below it, and it punishes large gaps much more than small ones — a gap of 10 counts contributes 100 times as much as a gap of 1. Dividing by E scales the gap to the size of the cell: being 5 counts out matters far more in a cell that expected 5 than in a cell that expected 500.
Then you add the cells up. A small χ² means the observed counts sit close to the expected ones — nothing surprising. A large χ² means at least some cells are far from expectation, and the pattern is unlikely to be chance. How large is “large” depends on the degrees of freedom, which you will meet in the worked examples below. The NIST/SEMATECH e-Handbook of Statistical Methods gives the same formula in its chapter on the chi-square goodness-of-fit test.
Run a Chi-Square Test in 5 Steps
Every chi-square test follows the same five steps, whether the table is 2×2 or 2×3, and whether you are testing goodness of fit or independence. Learn them once and you can run any of them.
- State the hypotheses: write down the null hypothesis (nothing is going on — the counts match what you expect) and the alternative (they do not). For the 2×2 example below, the null hypothesis is that the two variables are independent.
- Build the table: put your observed counts into a table, one row per group and one column per category, and add the row and column totals. Our 2×2 example has 60 observations in four cells.
- Compute the expected counts: for each cell, multiply its row total by its column total and divide by the grand total. In the 2×2 example every expected count is 15.
- Compute χ² and the degrees of freedom: for each cell work out (O − E)² ÷ E and add them up — here χ² = 6.667. The degrees of freedom are (rows − 1) × (columns − 1) = 1.
- Compare with the critical value and read the p-value: at α = 0.05 the critical value for 1 degree of freedom is 3.8415. Our χ² = 6.667 is larger, and p = 0.0098, so we reject the null hypothesis.
The steps are the same for goodness of fit, except the expected counts come from the claimed pattern instead of the row and column totals — you will see that in the die example below. If you want the critical value for your own degrees of freedom, see how to find a critical value. For the thinking behind step 1, read hypothesis testing explained.
Worked Example 1: The 2×2 Test of Independence
Sixty people were asked whether they prefer option A or option B. Thirty belong to group 1 and thirty to group 2. The question: does the preference depend on the group?
| Prefers A | Prefers B | Row total | |
|---|---|---|---|
| Group 1 | 10 | 20 | 30 |
| Group 2 | 20 | 10 | 30 |
| Column total | 30 | 30 | 60 |
Expected counts. Under independence, each cell should hold (row total × column total) ÷ grand total = (30 × 30) ÷ 60 = 15. All four expected counts are 15, so the expected table is perfectly flat: 15 in every cell.
| Cell | O | E | (O − E)² / E |
|---|---|---|---|
| Group 1, A | 10 | 15 | 1.667 |
| Group 1, B | 20 | 15 | 1.667 |
| Group 2, A | 20 | 15 | 1.667 |
| Group 2, B | 10 | 15 | 1.667 |
χ² and the decision. Adding the four contributions: χ² = 1.667 + 1.667 + 1.667 + 1.667 = 6.667. The degrees of freedom are (2 − 1) × (2 − 1) = 1, and the critical value at α = 0.05 is 3.8415. Since 6.667 > 3.8415, we reject independence: the preference does depend on the group. The p-value is 0.0098 — a pattern this strong would occur by chance only about 1 time in 100. Run the numbers yourself and check that you get the same answer.
Yates’ correction. Because counts are whole numbers and the chi-square distribution is continuous, the test slightly overstates the evidence in a 2×2 table. Yates’ correction subtracts 0.5 from each |O − E| before squaring: (5 − 0.5)² ÷ 15 = 1.350 per cell, so the corrected χ² = 5.400 and p = 0.0201. The conclusion is unchanged — still significant at 0.05 — but the correction is the honest number to report for a 2×2 table.
Cramér’s V. The p-value says the pattern is real; Cramér’s V says how big it is: V = √(χ² ÷ (n × (min(rows, columns) − 1))) = √(6.667 ÷ 60) = 0.333. On the usual scale (0.1 small, 0.3 medium, 0.5 large for 1 degree of freedom), that is a medium effect.
Standardized residuals. Which cells drive the result? The standardized residual for a cell is (O − E) ÷ √E. Here every cell gives (10 − 15) ÷ √15 = −1.291 or (20 − 15) ÷ √15 = +1.291. All four cells pull equally, so no single cell dominates — the whole table tilts the same way. A residual beyond ±2 would have marked a cell as the main driver.
Worked Example 2: Is the Die Fair?
This is a goodness-of-fit test: one variable (the face that comes up) checked against a claimed pattern (a fair die). A four-sided die was rolled 60 times. If it is fair, each face should come up about 15 times.
| Face | 1 | 2 | 3 | 4 | Total |
|---|---|---|---|---|---|
| Observed | 16 | 18 | 16 | 10 | 60 |
| Expected (fair) | 15 | 15 | 15 | 15 | 60 |
| (O − E)² / E | 0.067 | 0.600 | 0.067 | 1.667 | 2.400 |
Adding the contributions: χ² = 0.067 + 0.600 + 0.067 + 1.667 = 2.400. The degrees of freedom for goodness of fit are the number of categories minus 1: df = 4 − 1 = 3. The critical value at α = 0.05 is 7.8147, and our χ² = 2.400 is well below it. The p-value is 0.4936 — a result this uneven would happen by chance about half the time. There is no evidence the die is unfair. Face 4 contributed the most (1.667 of the 2.400) with only 10 rolls, but even that is an ordinary fluctuation. If you only cared about one face — say, whether face 4 comes up less often than 1 in 4 — that is a single-proportion question: the one-proportion z-test calculator is the sharper tool, and the exact probability for one face comes from the binomial probability calculator. For the idea behind counting single outcomes, see binomial distribution examples.
Worked Example 3: A 2×3 Table
The test works the same way when the table has more than two columns. Two groups chose between three options:
| Option A | Option B | Option C | Row total | |
|---|---|---|---|---|
| Group 1 | 10 | 15 | 5 | 30 |
| Group 2 | 20 | 10 | 15 | 45 |
| Column total | 30 | 25 | 20 | 75 |
Expected counts. Row 1: (30 × 30) ÷ 75 = 12, (30 × 25) ÷ 75 = 10, (30 × 20) ÷ 75 = 8. Row 2: (45 × 30) ÷ 75 = 18, (45 × 25) ÷ 75 = 15, (45 × 20) ÷ 75 = 12. So the expected rows are [12, 10, 8] and [18, 15, 12].
χ² and the decision. The six contributions are 0.333 + 2.500 + 1.125 + 0.222 + 1.667 + 0.750 = 6.597. The degrees of freedom are (2 − 1) × (3 − 1) = 2, and the critical value at α = 0.05 is 5.9915. Since 6.597 > 5.9915, we reject independence: the choice depends on the group. The p-value is 0.0369, and Cramér’s V = √(6.597 ÷ 75) = 0.297 — a small-to-medium effect. Notice the biggest single contribution (2.500) comes from group 1 choosing option B 15 times against 10 expected: that cell is where the pattern is strongest.
When Do I Use Goodness-of-Fit vs Independence?
The two tests answer different questions, and the question you ask decides which one to run:
| Goodness of fit | Independence | |
|---|---|---|
| Variables | One categorical variable | Two categorical variables |
| Question | Do these counts match a claimed pattern? | Are these two variables related? |
| Expected counts | From the claimed pattern (e.g. 15 each for a fair die) | From the row and column totals |
| Degrees of freedom | Categories − 1 | (rows − 1) × (columns − 1) |
| Example | Is this die fair? | Does preference depend on group? |
If your question has one variable and a pattern to check it against, it is goodness of fit. If it has two variables in a table, it is independence. When in doubt, count the variables.
Can I Use a Chi-Square Test on Percentages?
No — and this is the most common chi-square mistake. The test is computed from counts, and its result depends on how many observations those percentages represent. The same percentages can be meaningless with a small sample and decisive with a large one.
Take a 60/40 split between two options. With 10 people in each group the table is [[6, 4], [4, 6]] and χ² = 0.8 — nowhere near significant (p = 0.371). With 100 people in each group the percentages are identical, but the table is [[60, 40], [40, 60]] and χ² = 8.0 — significant (p = 0.005). Same percentages, opposite conclusions.
Always feed counts to the test, never percentages. If a report only gives you percentages, multiply them back by the sample size to recover the counts — and if the sample size is not given, the test cannot be run at all.
The same trap applies to rates and averages dressed up as counts. A “65% satisfaction rate” is not a count until you know 65% of how many. Percentages hide the sample size, and the sample size is exactly what gives a chi-square test its power.
What Does a Small P-Value Mean in a Chi-Square Test?
A p-value is the probability of getting a χ² at least as large as yours if the null hypothesis were true. For the 2×2 example, p = 0.0098 means: if preference really did not depend on group, a table this lopsided would turn up by chance only about 1 time in 100. That is small enough to doubt the null hypothesis — so we reject it.
Three things a p-value is not. It is not the probability that the null hypothesis is true — p = 0.0098 does not mean there is a 0.98% chance the variables are independent. It is not the size of the effect — that is Cramér’s V. And it is not a measure of importance: with a huge sample, even a trivial pattern becomes “significant”. Read what is a p-value for the full story, and if you want the p-value for a z-score, use the p-value calculator from z-score. A p-value is also not a standard error — for how the two differ, see standard error vs standard deviation.
The usual cut-off is α = 0.05: p below 0.05 is “significant”, p above it is not. But the cut-off is a convention, not a law of nature — p = 0.0369 (the 2×3 example) and p = 0.0098 (the 2×2) are both significant, yet the second is much stronger evidence. Report the p-value itself, not just “significant” or “not significant”.
The Expected-Count Rule: When Chi-Square Does Not Apply
The chi-square test is an approximation: it treats the discrete counts as if they followed the smooth chi-square distribution. That approximation breaks down when the expected counts are small. The standard rule is that every expected count should be at least 5 — and if any cell expects fewer than 5, do not run the chi-square test on that table.
Suppose a 2×2 table has an expected count of 2.3 in one cell. The (O − E)² / E contribution from that cell swings wildly with a single observation, and the p-value the test returns cannot be trusted. The fix depends on the table: for a 2×2 table, use Fisher’s exact test, which computes the exact probability instead of approximating it. For a larger table, combine categories that make sense together — merge two rare categories into one — until every expected count reaches 5.
Two more conditions complete the checklist: the observations must be independent (each person counted once, no pairing), and the data must be counts of things in categories, not measurements or percentages. Counts that arrive over time — calls per hour, defects per batch — are often better handled as Poisson data; see Poisson distribution examples.
How to Report a Chi-Square Test (APA)
A result is only useful if someone else can read it. The APA style for a chi-square test reports the test, the degrees of freedom, the sample size, the statistic, the p-value and the effect size, in one sentence:
A chi-square test of independence showed a significant association between group and preference, χ²(1, N = 60) = 6.67, p = .010, V = .33.
Read the pieces: χ²(1, N = 60) gives the test, the degrees of freedom (1) and the sample size (60); 6.67 is the statistic, rounded to two decimals; p = .010 is the p-value to three decimals (APA drops the leading zero); V = .33 is Cramér’s V. For the die example the sentence is: “A chi-square goodness-of-fit test found no evidence that the die was unfair, χ²(3, N = 60) = 2.40, p = .494.” If the p-value is below .001, write p < .001 instead of the exact value.
Always name the test (independence or goodness of fit), give the degrees of freedom, and include an effect size. A p-value on its own says the pattern is unlikely to be chance; without V, the reader cannot tell whether it matters. The critical values used above (3.8415, 5.9915, 7.8147) come from the chi-square distribution; other tests use their own tables — see how to read a t-table for the t distribution.
Chi-Square Test in Excel
Excel has a built-in function for the test of independence, but not a goodness-of-fit wizard — that one you build by hand.
Test of independence: put the observed counts in a range and the expected counts in a matching range, then use =CHISQ.TEST(actual_range, expected_range). It returns the p-value directly — for our 2×2 table it returns 0.0098. You still need to work out the expected counts yourself (row total × column total ÷ grand total), and the function does not give you χ² itself. For that, use =CHISQ.DIST.RT(χ², df): =CHISQ.DIST.RT(6.667, 1) returns 0.0098.
Goodness of fit: build it by hand. Put the observed counts in one column and the expected counts in the next, then in a third column compute =(O−E)^2/E for each row and sum the column with =SUM. With the die data the sum is 2.400; =CHISQ.DIST.RT(2.4, 3) gives the p-value 0.4936.
One warning: CHISQ.TEST does not apply Yates’ correction and does not check the expected-count rule. If any expected count is below 5, Excel will still give you a number — it just will not be a trustworthy one.
Frequently Asked Questions
What is a chi-square test?
A chi-square test compares observed counts with the counts expected if nothing were going on, using the statistic χ² = Σ(O − E)²/E. It is used for categorical data: goodness of fit (one variable against an expected pattern) and independence (two variables in a table).
When do I use goodness-of-fit vs independence?
Use goodness of fit when you have one categorical variable and a pattern to check it against — for example, whether a die is fair. Use independence when you have two categorical variables in a table and want to know whether they are related.
What is the chi-square formula?
χ² = Σ(O − E)²/E, summed over every cell: subtract the expected count E from the observed count O, square the difference, divide by E, and add the results. For our 2×2 example the four cells each contribute 1.667, giving χ² = 6.667.
How do I find the degrees of freedom?
For a table, df = (rows − 1) × (columns − 1). A 2×2 table has df = 1, a 2×3 table has df = 2. For goodness of fit with k categories, df = k − 1 — our die example with 4 faces has df = 3.
What does a small p-value mean?
It means a χ² as large as the one you got would be unlikely if the null hypothesis were true. For our 2×2 example p = 0.0098, so a pattern this strong would occur by chance only about 1 time in 100. It is not the probability that the null hypothesis is true.
What is Yates’ correction?
Yates’ correction adjusts the chi-square statistic for a 2×2 table by subtracting 0.5 from each |O − E| before squaring, because the continuous chi-square distribution only approximates the discrete counts. For our 2×2 it lowers χ² from 6.667 to 5.400 (p = 0.0201) — the conclusion is unchanged.
What is Cramér’s V?
Cramér’s V measures how strong the association is, on a scale from 0 to 1: V = √(χ² ÷ (n × (min(rows, columns) − 1))). For our 2×2, V = 0.333 — a medium effect. The p-value says whether the pattern is real; V says how big it is.
Can I use a chi-square test on percentages?
No. The test needs counts: χ² depends on the sample size, so the same percentages give different results for different totals. A 60/40 split is not significant with 10 observations per group (χ² = 0.8) but is significant with 100 per group (χ² = 8.0). Convert percentages back to counts first.
Check Tools
Try the numbers from this guide with the site’s free calculators:
Chi-Square Test Calculator
Enter your observed counts and get χ², the p-value, the Yates correction and Cramér’s V.
Try the chi-square test calculator →
P-Value Calculator from Z-Score
Turn a z-score into a two-tailed p-value.
Try the P-Value Calculator from Z-Score →
One-Proportion Z-Test Calculator
Test a single proportion against a claimed value.
Try the One-Proportion Z-Test Calculator →
Explore All Statistical Tools
See every calculator on the site in one place.
Browse all our statistical tools →
Check Articles
Go deeper with these guides:
Hypothesis Testing Explained
The framework behind the null hypothesis: how a test is set up and decided.
Read the guide →
What Is a P-Value
What p = 0.0098 really means, and what it does not.
Read the guide →
How to Find a Critical Value
Look up the 3.8415 and 7.8147 cut-offs used in this guide.
Read the guide →
How to Read a T-Table
Critical values for the t distribution, the same idea in another table.
Read the guide →