Chi Square Calculator
Chi Square Calculator
Test a list of counts for goodness of fit, a table up to 6 × 6 for independence, or turn a chi square statistic into a p value, with expected counts, each cell’s contribution, the critical value and a plain decision.
Chi square distribution
Observed and expected counts
χ² = Σ (O − E)² ÷ E. Goodness of fit: E = total × expected share, with categories − 1 − parameters estimated degrees of freedom. Independence: E = row total × column total ÷ grand total, with (rows − 1) × (columns − 1). p = Q(df ÷ 2, χ² ÷ 2), the area of the chi square curve beyond χ². Yates takes 0.5 off each |O − E| in a 2 × 2 table. The CSV, image and printed report contain the values you entered, nothing preloaded.
How to use this tool
Choose the test. Goodness of fit compares one list of counts, such as how often each face of a die came up, with equal shares, a ratio such as 9:3:3:1, percentages or expected counts. Independence takes a table of counts up to 6 × 6, one row per line or rows separated by semicolons, and asks whether the row a count falls in is related to its column. The third option turns a χ² value and its degrees of freedom from a report into a p value and critical values.
The input people most often get wrong is the data itself. The test needs counts, not percentages or averages: a 60 to 40 split is χ² = 4 in 100 coin flips but χ² = 40 in 1,000. Leave "parameters estimated" at 0 unless you estimated something about the expected distribution from the same data, such as the mean of a Poisson model, and pick the significance level before you look at the result.
What the calculation is doing
For each category or cell the tool works out (O − E)² ÷ E, where O is the observed count and E the expected one, and adds them up: χ² = Σ (O − E)² ÷ E. Dividing by E puts each gap on the scale of chance: missing by 10 when 10 were expected is a big miss, missing by 10 out of 1,000 is noise. For goodness of fit E = n × expected share, with categories − 1 degrees of freedom. For a table E = row total × column total ÷ n, the count each cell would hold if rows and columns were unrelated, with (rows − 1) × (columns − 1) degrees of freedom.
The p value is the chance of a χ² at least this large if the null hypothesis were true: the area under the chi square curve beyond the statistic, which is the regularized upper incomplete gamma function Q(df ÷ 2, χ² ÷ 2). The tool evaluates it with a power series while χ² ÷ 2 is below df ÷ 2 + 1 and a continued fraction beyond that, formulas 8.7.1 and 8.9.2 of the NIST Digital Library of Mathematical Functions, and finds the critical value by solving Q = α with Newton's method inside a bisection bracket.

What a chi square result can and cannot tell you
The statistic only follows the chi square curve approximately, and the match is good only when expected counts are big enough. The NIST Dataplot manual quotes Cochran: the approximation may be poor if any expected count is below 1 or more than 20% are below 5. For a fair die rolled 60 times, 10 expected per face, it holds up: in 100,000 simulated experiments 4.72% crossed the 5% critical value.
Significance is not size. For the same proportions χ² grows with the sample, so thousands of observations make trivial differences significant. That is why the tool reports an effect size, w = √(χ² ÷ n), for which Cohen suggested 0.1 as small, 0.3 as medium and 0.5 as large, plus Cramér's V for tables. The loaded die in the default example has w = 0.47, near the large mark, and it took only 60 rolls to show.
A p value near 1 deserves a look too. Mendel's dihybrid count of 556 peas fits 9:3:3:1 with χ² = 0.470 and p = 0.925, unremarkable on its own. But when R. A. Fisher pooled Mendel's experiments in 1936 the total came to 41.6056 on 84 degrees of freedom. Fisher printed P = 0.99993, a fit that chance would match or beat about 7 times in 100,000; this tool's engine puts the upper tail at 0.99997, nearer 3 in 100,000. The lesson carries over to lab and inspection data: results that agree with expectation too well are worth asking about.
Critical values of the chi square distribution
Upper tail values from the calculator's engine. Reject the null hypothesis when χ² is larger than the value for your degrees of freedom and significance level α.
| Degrees of freedom | α = 0.1 | α = 0.05 | α = 0.025 | α = 0.01 | α = 0.001 |
|---|---|---|---|---|---|
| 1 | 2.706 | 3.841 | 5.024 | 6.635 | 10.828 |
| 2 | 4.605 | 5.991 | 7.378 | 9.210 | 13.816 |
| 3 | 6.251 | 7.815 | 9.348 | 11.345 | 16.266 |
| 4 | 7.779 | 9.488 | 11.143 | 13.277 | 18.467 |
| 5 | 9.236 | 11.070 | 12.833 | 15.086 | 20.515 |
| 6 | 10.645 | 12.592 | 14.449 | 16.812 | 22.458 |
| 7 | 12.017 | 14.067 | 16.013 | 18.475 | 24.322 |
| 8 | 13.362 | 15.507 | 17.535 | 20.090 | 26.124 |
| 9 | 14.684 | 16.919 | 19.023 | 21.666 | 27.877 |
| 10 | 15.987 | 18.307 | 20.483 | 23.209 | 29.588 |
| 12 | 18.549 | 21.026 | 23.337 | 26.217 | 32.909 |
| 15 | 22.307 | 24.996 | 27.488 | 30.578 | 37.697 |
| 20 | 28.412 | 31.410 | 34.170 | 37.566 | 45.315 |
| 30 | 40.256 | 43.773 | 46.979 | 50.892 | 59.703 |
| 50 | 63.167 | 67.505 | 71.420 | 76.154 | 86.661 |
| 100 | 118.498 | 124.342 | 129.561 | 135.807 | 149.449 |
A worked example you can check on paper
The default die came up 5, 8, 9, 8, 10 and 20 times in 60 rolls. A fair die should show each face 60 ÷ 6 = 10 times, so the contributions are (5 − 10)² ÷ 10 = 2.5, then 0.4, 0.1, 0.4 and 0, and (20 − 10)² ÷ 10 = 10 for the sixes. They add up to χ² = 13.40 with 6 − 1 = 5 degrees of freedom, past the 5% critical value of 11.070 in the table, so a fair die is rejected. The exact p value is Q(2.5, 6.7) = 0.0199: in 100,000 simulated sets of 60 fair rolls, 1.98% reached 13.4 or more. Roll a virtual die with the Random Number Generator and test your own counts.
For a table, the NIST/SEMATECH handbook counts 309 wafer defects by shift and type. Shift 1 had 94 defects and type A 74 of all 309, so that cell expects 94 × 74 ÷ 309 = 22.51 against 15 observed, contributing (15 − 22.51)² ÷ 22.51 = 2.51. The twelve contributions total χ² = 19.18 on (3 − 1) × (4 − 1) = 6 degrees of freedom, above the critical value of 12.592, with p = 0.00387, as the handbook reports.
Mistakes that catch people out
Entering percentages. Converting counts to percentages throws away the sample size, which is what decides whether a difference is convincing. Enter the raw counts and let the tool work out the shares.
Wrong degrees of freedom. Goodness of fit uses categories − 1, not the number of categories, and one fewer again for each parameter fitted from the same data. A table uses (rows − 1) × (columns − 1).
Checking observed counts instead of expected. The small count rule is about expected counts. An observed 0 is fine if 8 were expected; an expected 1.5 is a problem whatever was observed.
Counting a subject twice. Each observation must land in exactly one cell and be independent of the rest. Before and after answers from the same people need McNemar's test.
Reading "not significant" as "proven equal". A p value above 0.05 only means these data cannot rule the null hypothesis out. Small samples let even a clearly loaded die pass, so look at the effect size as well.
Popular calculations
Each opens the calculator with those counts filled in and tested at the 5% level; change anything once it is open.
Dice and coins
Mendel's peas and other expected ratios
2 × 2 tables
Larger tables
P values for common chi square values
How this was checked
Critical values were compared with the upper tail table in the NIST/SEMATECH handbook, section 1.3.6.7.4: 145 values for 1 to 100 degrees of freedom at five levels. 143 match to the three printed decimals; the other two, both at 0.001, are 26.124 against 26.125 for 8 degrees of freedom and 32.909 against 32.910 for 12, where the unrounded values are 26.12448 and 32.90949 and SciPy agrees with the tool.
An independent script computed the p value four other ways: the DLMF power series with its own Stirling log gamma, the DLMF continued fraction evaluated from the bottom up, the Poisson sum for even degrees of freedom and numerical integration of the density. At 209 points from 1 to 100 degrees of freedom all agree with the tool within 1.3 × 10⁻¹³. In 200,000 simulated sums of squared normal values for each of 1, 2, 3, 5 and 10 degrees of freedom, the share beyond the 5% critical value came out between 4.95% and 5.04%.
Published results were reproduced: the NIST handbook wafer table in section 7.4.5 (χ² = 19.18, critical value 12.5916, p = 0.00387, and eleven of the twelve expected counts to two decimals; the handbook prints the shift 2, type A cell as 22.9 where 96 × 74 ÷ 309 = 22.99), the 4 × 4 hair and eye colour table of 592 students in the NIST Dataplot manual (χ² = 138.2898, Cramér coefficient 0.279), a LibreTexts 2 × 2 example (4.7166 with p = 0.02987, and 3.3224 with p = 0.06834 after the Yates correction) and Mendel's 556 peas from his 1866 paper against 9:3:3:1 (χ² = 0.470 by hand). Every address above was loaded and checked for a distinct title, the right answer and no undefined values, and addresses in each of the three modes were checked by eye at desktop and phone widths with their exports.
Common questions
How do you calculate chi square?
For each category or cell, square the difference between the observed and expected counts, divide by the expected count and add up the results: χ² = Σ (O − E)² ÷ E. For 60 die rolls of 5, 8, 9, 8, 10 and 20 against 10 each, that is 2.5 + 0.4 + 0.1 + 0.4 + 0 + 10 = 13.4.
How do you find the degrees of freedom?
For goodness of fit, the number of categories minus 1, less one more for each parameter estimated from the same data. For a table, (rows − 1) × (columns − 1), so a 3 × 4 table has 6.
How do you get a p value from a chi square statistic?
It is the area under the chi square curve to the right of the statistic, the regularized upper incomplete gamma function Q(df ÷ 2, χ² ÷ 2). Choose the p value option above and enter χ² and the degrees of freedom: 3.84 with 1 degree of freedom gives 0.05004.
What is the critical value of chi square at 0.05?
It depends on the degrees of freedom: 3.841 for 1, 5.991 for 2, 7.815 for 3, 9.488 for 4, 11.070 for 5 and 18.307 for 10. A χ² above the critical value means p is below 0.05.
What if some expected counts are below 5?
The p value then becomes unreliable. Cochran's guideline is no expected count below 1 and no more than 20% below 5. If yours fail it, merge sparse categories, collect more data, or use an exact test such as Fisher's exact test for a 2 × 2 table.
Should I use the Yates correction?
It applies only to 2 × 2 tables, where it takes 0.5 off each |O − E| before squaring. It is often too cautious: in 200,000 simulated tables of 45 observations with no real association, the plain test rejected 5.1% of the time at the 5% level and the corrected test only 2.0%. For small samples Fisher's exact test is the better choice.
Related Calculators and Reference
- T Test Calculator: compare averages rather than counts between two groups.
- Binomial Distribution Calculator: exact probabilities for two outcomes, such as heads in a run of coin flips.
- Dice Probability Calculator: the exact chances behind the expected counts for dice.
- Confidence Interval Calculator: a range for one proportion once the test says the shares differ.
- Sample Size Calculator: plan how many responses a survey needs before you tabulate them.
- Poisson Distribution Calculator: the Poisson chance of each count, which gives the expected counts for a goodness of fit test.
- P Value Calculator: look up the p value or critical value from a chi square statistic, or for z, t and F.
- NIST/SEMATECH Handbook: Critical Values of the Chi Square Distribution: the table the critical values here were checked against.
