Chi-Square Calculator – Does What You Observed Match What You Expected?
You counted something in categories and you have an expected split in mind. This test measures how far your counts sit from that expectation, in one number, and turns it into a p-value so you can judge whether the gap is plausibly just chance.
Your counts
Separate counts with commas, spaces or new lines. You need at least 2 categories.
Expected counts come from your theory or model, not from the observed data. Every expected count must be greater than 0.
Your numbers never leave this page. Everything is calculated in your browser.
Result
The numbers behind it
Below your significance level, the gap between observed and expected is statistically significant. It is a guide, not a proof: a small p-value can still come from a fluke, and a large one does not prove the model is exactly right.
- Each category contributes its squared gap divided by its expected count, and the contributions add up to the chi-square statistic.
- On the defaults the statistic is 10.00 with p 0.0067, judged Significant at the 0.05 level.
- The biggest contributions point at the categories where reality and expectation disagree most — read those first, before trusting the verdict.
- Where the statistic comes from, category by category
- How it works, in three steps
- How the calculation works
- Going deeper
- Reading a chi-square result the way a sceptic would
- When the test fits, when it does not, and what small expected counts do
- Building an expectation, and checking it before you test
- Worked checks: from contributions to verdict, by hand
- Frequently asked questions
Where the statistic comes from, category by category
Each category adds its own squared gap, scaled by what was expected. Big contributions point at the categories where reality and expectation disagree most.
| Category | Observed | Expected | Gap (O minus E) | Contribution | Share of total |
|---|---|---|---|---|---|
| 1 | 10 | 20 | -10 | 5.00 | 50.0% |
| 2 | 20 | 20 | 0 | 0.00 | 0.0% |
| 3 | 30 | 20 | 10 | 5.00 | 50.0% |
Related tools
How it works, in three steps
Type both lists
Observed counts are what you actually counted. Expected counts are what your theory predicts, in the same order and with the same number of categories.
Read the statistic
Each category contributes its squared gap divided by its expected count. Categories where reality and expectation disagree most contribute the most.
Judge with the p-value
The p-value is the chance of a gap at least this big if the expected model were true. Below your level, the gap is statistically significant.
How the calculation works
χ² = Σ((O minus E)² ÷ E) · degrees of freedom = categories minus 1
Worked example. Observed 10, 20, 30 against expected 20, 20, 20. Contributions: (10 minus 20)² ÷ 20 = 5.00, (20 minus 20)² ÷ 20 = 0.00, (30 minus 20)² ÷ 20 = 5.00. Total χ² = 10.00 with df = 3 minus 1 = 2, giving p = 0.0067, significant at 0.05.
Second example. Observed 5, 15 against expected 10, 10. Contributions: 25 ÷ 10 = 2.50 and 25 ÷ 10 = 2.50, so χ² = 5.00 with df = 1, giving p = 0.0253, also significant at 0.05.
Perfect match example. Observed 20, 20, 20 against expected 20, 20, 20. Every gap is 0, so χ² = 0.00 and p = 1.0000: the data match the model exactly.
Four-category example. Observed 12, 18, 25, 45 against expected 25, 25, 25, 25. Contributions: 6.76, 1.96, 0.00 and 16.00, so χ² = 24.72 with df = 3, giving p = 0.0000 to four decimals, clearly significant.
Going deeper
This test is for counts in categories: survey answers, dice rolls, defect types, or any split where each observation lands in exactly one bucket. It is not for measurements like heights or times, and it is not for comparing two averages. If your data are two lists of counts that should follow the same split, the goodness-of-fit test fits. If you are comparing two different groups across categories, that is a test of independence, which uses the same statistic on a table instead of two lists.
The chi-square approximation works best when expected counts are not tiny. The common guideline is that every expected count should be at least 5. This page warns you when an expected count falls below 5 but still computes, so you can decide whether to combine small categories or use an exact test instead. A small p-value says the gap is unlikely to be pure chance under your model, not that you have found the true cause. A large p-value says the data are compatible with the model, not that the model is proven exactly right.
Reading a chi-square result the way a sceptic would
A chi-square result has four parts, and each one answers a different question, so read them in order and do not let any one of them stand in for the rest. The statistic measures how far the observed counts sit from the expected counts, with each gap squared and scaled by its expected count. The degrees of freedom record how many independent comparisons the data contain, which is the number of categories minus 1. The p-value translates the statistic into a probability: the chance of a gap at least this big if the expected model were exactly true. The verdict compares that p-value with the significance level you chose in advance and calls the gap significant or not. The default case on this page shows all four working together: observed 10, 20, 30 against expected 20, 20, 20 gives a statistic of 10.00 with 2 degrees of freedom, a p-value of 0.0067, and a verdict of Significant at 0.05. Every figure in this section was read from the calculator’s own displayed results for the stated inputs.
The contributions table is where the statistic stops being a single mysterious number and becomes an explanation. In the default case, category 1 contributes 5.00, from a gap of minus 10 squared and divided by 20, category 2 contributes 0.00, from a gap of 0, and category 3 contributes 5.00, from a gap of plus 10 squared and divided by 20. The two outer categories share the statistic equally, 50.0 percent each, and the middle category contributes nothing, because it matched its expectation exactly. That split is the most useful sentence in the whole result: the disagreement lives in categories 1 and 3, in opposite directions, and category 2 is not part of the story. A reader who reports only the statistic of 10.00 has hidden that structure; a reader who reports the contributions has explained where to investigate next, which is the low count in category 1, the high count in category 3, or the expectation itself, which may be wrong for both.
The four-category example on the page shows the same reading at a larger scale, and it is worth working through because one category dominates it. Observed 12, 18, 25, 45 against expected 25, 25, 25, 25 gives contributions of 6.76, 1.96, 0.00, and 16.00, a statistic of 24.72 with 3 degrees of freedom, and a p-value of 0.0000 to four decimals, clearly significant at 0.05. Category 4 alone contributes 16.00, which is about 65 percent of the total, from a gap of plus 20 squared and divided by 25. Category 1 contributes 6.76 from a gap of minus 13, category 2 contributes 1.96 from a gap of minus 7, and category 3 contributes nothing. The story of that result is therefore a story about category 4 first, category 1 second, and the other two categories barely at all. If the investigation that follows looks at all four categories equally, it wastes most of its effort on the two that agree with the model.
| Case | Statistic | df | p-value | Verdict at 0.05 | Largest contributor |
|---|---|---|---|---|---|
| 10, 20, 30 vs 20, 20, 20 (default) | 10.00 | 2 | 0.0067 | Significant | Categories 1 and 3, 5.00 each |
| 5, 15 vs 10, 10 | 5.00 | 1 | 0.0253 | Significant | Both categories, 2.50 each |
| 20, 20, 20 vs 20, 20, 20 (perfect match) | 0.00 | 2 | 1.0000 | Not significant | None: every gap is 0 |
| 12, 18, 25, 45 vs 25, 25, 25, 25 | 24.72 | 3 | 0.0000 | Significant | Category 4, 16.00 |
| 10, 20, 30 vs 20, 20, 30 (totals differ) | 5.00 | 2 | 0.0821 | Not significant | Category 1, 5.00 (the whole statistic) |
The last row of that table is worth unpacking, because its statistic comes from a single category. For observed 10, 20, 30 against expected 20, 20, 30, the contributions are: category 1, a gap of minus 10 squared divided by 20, which is 5.00; category 2, a gap of 0, which is 0.00; category 3, a gap of 0, which is 0.00. The statistic is therefore 5.00, entirely from category 1, with 2 degrees of freedom and a p-value of 0.0821, which is Not significant at 0.05. The totals in that case differ, 60 observed against 70 expected, and the page still computes while showing both totals, as the base guide says it warns when totals differ. A totals mismatch is not a calculation error; it is a modelling signal, because expected counts are usually built from the same total as the observed counts, and a mismatch means the expectation was built differently, which must be understood before the p-value is trusted.
That totals case also teaches the most important lesson about p-values on this page: the same statistic can give different verdicts depending on the degrees of freedom and the level. A statistic of 5.00 with 1 degree of freedom gives a p-value of 0.0253 and is Significant at 0.05. The same statistic of 5.00 with 2 degrees of freedom gives a p-value of 0.0821 and is Not significant at 0.05. The statistic alone does not determine the verdict; the degrees of freedom do, because a given gap is less surprising when it is spread across more categories. And the level matters just as much: the 5, 15 against 10, 10 case, with a p-value of 0.0253, is Significant at 0.05 but Not significant at 0.01, as the calculator shows when the level selector is changed. A verdict without its level and its degrees of freedom is an incomplete sentence, and any report of a chi-square result should carry all four parts: the statistic, the degrees of freedom, the p-value, and the level.
When the test fits, when it does not, and what small expected counts do
The chi-square goodness-of-fit test fits one shape of data and no other: counts in categories, where each observation lands in exactly one bucket. Survey answers, dice rolls, defect types, and any split where the question is whether the observed split matches an expected split are in scope. Measurements such as heights or times are not, because they are not counts in buckets, and comparing two averages is not, because averages are not splits. If your data are two lists of counts that should follow the same split, this test fits. If you are comparing two different groups across categories, that is a test of independence, which uses the same statistic on a table instead of two lists, and this page’s two-list form is not the right tool for it, even though the arithmetic looks similar. Matching the tool to the data shape matters more than getting the arithmetic right, because correct arithmetic on the wrong test gives a confident wrong answer.
Expected counts deserve as much care as observed counts, because they carry the theory being tested, and a careless expectation makes the whole result meaningless. Expected counts come from your theory or model, not from the observed data, as the page itself states beside the expected box. Building expected counts from the observed data, for example by setting each expected count to the observed average, guarantees a small statistic and a large p-value, and proves nothing, because the theory was fitted to the data it is supposed to test. A genuine expectation comes from outside the data: a published split, a theoretical distribution such as a fair die’s equal sixths, a previous study’s proportions, or a model’s predictions made before the counts were collected. State the source of the expectation alongside the result, because a p-value without its expectation is a verdict without a charge: it says the data disagree with something, but not with what.
The expected-counts rule is the page’s main warning, and it is stated twice on the page, in the guide and in the FAQ, because it is the rule most often ignored. The chi-square approximation works best when expected counts are not tiny, and the common guideline is that every expected count should be at least 5. This page warns you when an expected count falls below 5 but still computes, so you can decide whether to combine small categories or use an exact test instead. Combining categories means merging two small buckets into one larger bucket before testing, which changes the number of categories and therefore the degrees of freedom, and it must be decided on substantive grounds, not by trying combinations until the verdict flips. An exact test, such as Fisher’s exact test for two categories, does not rely on the approximation at all, and for small samples it is the more appropriate choice, as the page’s own educational note says. A significant result from tiny expected counts should be treated as a prompt to gather more data or to combine categories honestly, not as a finding.
Order matters in a way that is easy to overlook: observed and expected counts are paired by position, so the first observed count is compared with the first expected count, the second with the second, and so on. Reordering one list without reordering the other pairs the wrong counts together and produces a statistic for a comparison nobody intended. The page requires the two lists to have the same length, and it requires at least 2 categories, because a single category has 0 degrees of freedom and nothing to test. Separators are flexible, commas, spaces, or new lines, which is convenient, but flexibility is also a trap: a stray comma creates an empty entry, and a missing separator merges two counts into one, changing both the category count and the degrees of freedom. Count the entries in each list before you read the result, and confirm the category count shown matches the count you intended, because every downstream number, the statistic, the degrees of freedom, and the p-value, follows from that count.
What a p-value does not say is the last and most important section of any honest guide to this test, and the base guide states it twice, in the result panel and in the FAQ, because it is the most common misreading in statistics. A small p-value says the gap would be unlikely if the theory were exactly true, but it does not identify what is wrong, and it can still arise by chance: at a 0.05 level, about one test in twenty of a true theory will come out significant by luck alone. A large p-value says the data are compatible with the model, not that the model is proven exactly right, and a perfect match, with a statistic of 0.00 and a p-value of 1.0000, says only that the counts equal the expectation, which can happen by luck in a small sample or by construction if the expectation was built from the data. Treat every result as evidence to investigate, not as a final verdict, and report the statistic, the degrees of freedom, the p-value, and the level together, so that any reader can judge the evidence for themselves.
Building an expectation, and checking it before you test
Before typing any counts, write the expectation down in words, because a test without a written expectation is a fishing expedition. A fair die should land equally on all six faces, so the expected counts for 60 rolls are 10 in each category. A survey population that is 50 percent one group and 50 percent another should split a sample of 100 into 50 and 50. A machine that historically produces defects in a known ratio should produce new counts in that ratio. Each of those sentences becomes an expected list by multiplying the proportions by the total, and the total used must be the observed total if the expectation is a split of the same sample. If the proportions do not multiply to whole numbers, keep the decimals in the expected list rather than rounding to integers, because rounding changes the gaps and therefore the statistic, and the page accepts decimal expected counts as readily as whole ones, since it only requires each expected count to be greater than 0.
Check the expectation against the observed total before testing, because a totals mismatch is the most common sign that the expectation was built for a different sample. The probed totals case on this page, observed 60 against expected 70, still computed, giving a statistic of 5.00 and a p-value of 0.0821, but the expectation described a sample of 70 while the data described a sample of 60, so the comparison mixed two different scales. The correct response to a totals warning is not to accept the result anyway, but to ask which total is right: if the expectation proportions are right, rescale them to the observed total and test again; if the expected total is right, ask why the observed total differs, because counts may be missing or double-counted. Either answer changes the test, and accepting the warned result without asking is how a totals warning becomes a false conclusion.
Finally, decide the significance level before you see the result, not after, because choosing the level after seeing the p-value lets you pick the verdict you prefer. The page offers 0.10, 0.05, and 0.01, and the usual practice, as the base FAQ says, is to choose in advance, most often 0.05. The probed level case shows why the choice matters: a p-value of 0.0253 is Significant at 0.05 and Not significant at 0.01, so a reader who chooses the level after seeing 0.0253 can report either verdict honestly by the letter of the rule while misleading by its spirit. Write the level down with the expectation, before the counts go in, and report the p-value itself alongside the verdict, so that a reader who prefers a different level can re-judge the same evidence without re-running the test. A p-value reported without its level is a verdict without its standard, and a standard chosen after the fact is not a standard at all.
Worked checks: from contributions to verdict, by hand
The statistic is simple enough to check by hand, and the hand check is the fastest way to learn what each category contributes. Take the default case: observed 10, 20, 30 against expected 20, 20, 20. Category 1: 10 minus 20 is minus 10, squared is 100, divided by 20 is 5.00. Category 2: 20 minus 20 is 0, squared is 0, divided by 20 is 0.00. Category 3: 30 minus 20 is 10, squared is 100, divided by 20 is 5.00. The total is 10.00, the degrees of freedom are 3 minus 1, which is 2, and the p-value the calculator reports for that statistic with 2 degrees of freedom is 0.0067. The p-value itself is not computed by hand here, because it comes from the chi-square distribution, but the statistic is fully checkable, and any hand statistic that disagrees with the page’s statistic points to a pairing error, a separator error, or an expected count typed in the wrong position.
Check the two-category case the same way, because it shows why degrees of freedom matter. Observed 5, 15 against expected 10, 10: category 1 gives 25 divided by 10, which is 2.50, and category 2 gives 25 divided by 10, which is also 2.50, for a statistic of 5.00 with 1 degree of freedom and a p-value of 0.0253. The statistic is half the default case’s statistic, yet the p-value is larger, 0.0253 against 0.0067, because with only 1 degree of freedom the distribution is different, and a statistic of 5.00 is less surprising when there are fewer categories to spread it across. Readers who compare statistics across tests with different degrees of freedom are comparing numbers on different scales, and the p-value is the common scale, not the statistic. Always carry the degrees of freedom with the statistic, and compare p-values, not raw statistics, across different category counts.
The perfect-match case is the check that calibrates the whole scale. Observed 20, 20, 20 against expected 20, 20, 20 gives gaps of 0 in every category, contributions of 0.00, a statistic of 0.00, and a p-value of 1.0000. That is the smallest possible statistic and the largest possible p-value, and it means the data match the model exactly, nothing more. It does not mean the model is true, because a small sample can match any model by luck, and it does not mean the model will match the next sample. Use the perfect match as the zero point of the scale: every real result sits between 0.00 and whatever the data produce, and the p-value tells you how far along that scale counts as surprising. A statistic near zero with a p-value near 1 is compatible with the model; a statistic far from zero with a p-value below your level is not, and the distance that counts as far depends on the degrees of freedom.
One more hand check guards against the subtlest error on this page: a sign error in the gap. The gap is observed minus expected, and squaring removes the sign, so a category 10 below expectation and a category 10 above expectation contribute equally, 5.00 each in the default case. That symmetry is correct for the statistic, but it hides the direction, which is why the contributions table shows the signed gap alongside the contribution. Read the signs when you investigate: two categories deviating in opposite directions suggest a shift between categories, while several categories deviating in the same direction suggest a totals problem or a wrong expectation. The statistic cannot tell those stories apart, because it squares the gaps away, and the signed gaps in the table are the only place the direction survives. Report the directions with the statistic, or the investigation that follows will start blind.
Small expected counts: the remedies, in order
When an expected count falls below 5, the usual advice is not to abandon the test but to change how the table is handled, in this order. First, check whether the small expectation is a data problem: a miscoded category, a totals error, or a category that should never have been split. The signed gaps in the worked checks above are the fastest way to spot a category that contributes almost nothing except noise.
Second, combine categories that belong together in substance, not merely to reach the threshold. Merging two genuinely similar outcomes changes the question slightly and honestly; merging unlike outcomes to manufacture a pass changes the question dishonestly. Third, for a 2-by-2 table, consider the Yates continuity correction, which subtracts 0.5 from each absolute gap before squaring, pulling the statistic down toward the value a continuous distribution would give. Fourth, use Fisher’s exact test, which computes the probability of the table directly instead of approximating it, and which needs no minimum expected count at all. Fisher’s test is the standard answer for small 2-by-2 tables, and the calculator’s chi-square result should be read alongside it, not instead of it.
Degrees of freedom in larger tables
For a goodness-of-fit test the degrees of freedom are the number of categories minus 1, because the total fixes one count. For a test of independence on a table with r rows and c columns, the degrees of freedom are (r minus 1) times (c minus 1): each row total and each column total is a constraint, and only the inner cells that remain free count. A 2-by-3 table therefore has 2 degrees of freedom, and a 3-by-3 table has 4.
The practical consequence is that larger tables need a larger statistic to reach the same p-value, because more free cells give chance more room to produce gaps. That is why the same statistic of 11.25 is strong evidence in a 2-by-2 table and weaker evidence in a 4-by-4 table: the verdict always travels with the degrees of freedom, and reporting one without the other leaves the result uninterpretable. The companion guides work both cases by hand, so the difference can be seen in the arithmetic rather than taken on trust.
Frequently asked questions
What does the chi-square statistic actually measure?
It measures the total squared gap between observed counts and expected counts, with each gap scaled by its expected count. A value of 0 means a perfect match, and larger values mean a bigger disagreement.
Why are degrees of freedom equal to categories minus 1?
Once you know the total count and all but one category count, the last count is fixed, so one degree of freedom is lost. With 3 categories you have 2 degrees of freedom, and with 2 categories you have 1.
What is a good p-value for a chi-square test?
There is no universal good value. The usual practice is to compare the p-value with a level chosen in advance, most often 0.05. Below that level the gap is called statistically significant, which is a guide for judgment, not a proof.
Can I use this test when an expected count is below 5?
The chi-square approximation gets shaky with very small expected counts, and the common guideline is that every expected count should be at least 5. This page warns you in that case and still computes, so you can combine small categories or switch to an exact test.
Do the observed and expected totals have to match?
Normally they do, because expected counts are usually built from the same total as the observed counts. This page warns you if the totals differ, but it still computes, since some models define expected counts independently.
Is a significant result proof that my theory is wrong?
No. A small p-value says the gap would be unlikely if the theory were exactly true, but it does not identify what is wrong, and it can still arise by chance. Treat it as evidence to investigate, not as a final verdict.
What does the same data look like at a stricter significance level?
The verdict can flip even though the statistic does not change. Observed 5, 15 against expected 10, 10 gives a statistic of 5.00 with 1 degree of freedom and a p-value of 0.0253, which is Significant at 0.05 but Not significant at 0.01, because 0.0253 sits between the two levels. That is why the level must be chosen before you see the result, not after: choosing afterwards lets you pick the verdict you prefer from the same evidence.
What if my observed and expected totals do not match?
The calculator still computes and shows both totals, but a mismatch is a modelling signal to resolve before trusting the p-value. Observed 10, 20, 30 against expected 20, 20, 30 gives a statistic of 5.00 with 2 degrees of freedom and a p-value of 0.0821, Not significant at 0.05, with totals of 60 observed against 70 expected. Normally the expected counts are built from the same total as the observed counts, so rescale the expectation to the observed total, or find why the totals differ, before accepting the result.
How do I read a four-category result?
Read the contributions, not just the statistic. Observed 12, 18, 25, 45 against expected 25, 25, 25, 25 gives contributions of 6.76, 1.96, 0.00, and 16.00, a statistic of 24.72 with 3 degrees of freedom, and a p-value of 0.0000 to four decimals, clearly significant at 0.05. Category 4 alone contributes 16.00, about 65 percent of the total, so the investigation should start with category 4, then category 1, and barely touch the categories that already agree with the model.
Why is a p-value of 1.0000 not proof my model is exactly right?
Because a p-value of 1.0000 only says the counts match the expectation exactly, which can happen by luck in a small sample or by construction if the expectation was built from the data. Observed 20, 20, 20 against expected 20, 20, 20 gives a statistic of 0.00 and a p-value of 1.0000, meaning the data are compatible with the model, not that the model is proven true. A large p-value is compatibility, not proof, just as a small p-value is evidence to investigate, not a final verdict.
What is the Yates continuity correction, and when should I use it?
The Yates correction subtracts 0.5 from each absolute difference between observed and expected counts before squaring, for a 2-by-2 table. It compensates for approximating a discrete distribution with a continuous one, and it makes the test more conservative: the statistic falls and the p-value rises. Use it for small 2-by-2 tables, and prefer Fisher’s exact test when the counts are very small.
When is Fisher’s exact test better than a chi-square test?
Fisher’s exact test computes the exact probability of the observed table under independence, instead of approximating it with the chi-square distribution. It is the better choice for 2-by-2 tables with small expected counts, where the chi-square approximation is unreliable. For large tables with comfortable expected counts, the two tests usually agree, and chi-square is far easier to compute by hand.
How is a chi-square test different from a t-test?
A chi-square test works on counts in categories; a t-test works on means of measured values. If the data are how many people fell into each group, chi-square is the tool. If the data are measurements such as weights or times and the question is whether two group averages differ, the t-test is the tool. The two tests answer different questions, and neither substitutes for the other.
What if my categories have a natural order, such as dose levels?
The chi-square test ignores order: it treats the categories as labels, so a steady trend across ordered groups and a scattered pattern can give the same statistic. When order matters, a trend test that uses the ordering carries more information and more power. Report the chi-square result as a test of any association, and use the trend test for the directional question.
Standard Error Calculator
How precise a sample mean is.
nSample Size Calculator
How many observations you need.
ΣStatistics Calculator
Mean, median, variance and more.
pProbability Calculator
Chances for single events.
x̄Average Calculator
Mean of any list of numbers.
📊Chi-Square Test Worked Examples
2×2 tables and expected values, worked by hand.
📈Chi-Square Goodness of Fit and Test of Independence
Which test fits, and how the two differ.
Educational tool only. The chi-square goodness-of-fit test is a statistical guide, not statistical advice for any specific study. Results depend on the expected counts you enter and on the expected-counts guideline described above. For small samples, exact tests may be more appropriate than this approximation.