Quick answer: a chi-square test compares the counts you observed with the counts you would expect if nothing interesting were going on — two variables independent, or a distribution matching its claimed shape. This chi square test calculator does all three jobs: build a contingency table up to 5 × 5 for a chi square test of independence, paste observed and expected lists for a chi square goodness of fit test, or convert a finished statistic into its chi square p value in lookup mode. The worked check to try first: the table 30, 20 / 20, 30 gives χ² = 4.000, df = 1, p = 0.0455.

How to use this chi square calculator

Step 1 — Pick the mode that matches your question. Table mode is for a chi square test of independence: you have counts cross-classified by two categorical variables, such as clinic (two sites) by outcome (recovered or not). Goodness-of-fit mode is for one list of categories tested against one expected distribution. Lookup mode skips the counts entirely: you already have a χ² statistic from software, a textbook or a paper, and you want its p-value.

Step 2 — Enter counts, not percentages. In table mode, set the row and column counts first, then type the observed count in each cell. In goodness-of-fit mode, paste the observed counts and the expected counts as comma-separated lists of the same length. Every keystroke recalculates: expected counts, the χ² statistic, the degrees of freedom and the p-value all update live, and any expected count below 5 triggers a visible warning rather than a silent footnote.

Step 3 — Read the result in the right order. Check the expected counts first (are any of them worryingly small?), then the statistic and its degrees of freedom, then the exact p-value against the significance level you chose before looking at the data. The verdict line reports α = 0.05 and α = 0.01, but the exact p-value is the real output. If you also need a p-value from a t, z or F statistic, the companion P-Value Calculator covers those distributions in the same style.

What a chi-square test is — and what it is not

In short: the chi-square test is a discrepancy meter for counts. It asks how far your observed frequencies sit from the frequencies a specific boring explanation predicts, scaled by how much wobble chance alone would produce. Karl Pearson introduced the test in 1900, and it remains the default tool whenever the data are tallies in categories rather than measurements on a scale.

The statistic itself is a sum over cells: χ² = Σ (O − E)² / E. Dividing by E is the crucial move. A gap of 5 counts is unremarkable in a cell expecting 500 and damning in a cell expecting 8, and the division puts both on the same footing. Squaring keeps positive and negative gaps from cancelling and penalises big misses more than small ones. The result is a single number that grows as the data drift from the null's prediction — and, just as importantly, grows with sample size, because the same proportional drift in a bigger sample is harder to blame on chance.

Two misreadings follow the test everywhere, and this page will keep correcting them. First, a significant chi-square result shows association, not causation: the test sees two variables moving together and cannot say which moves which, or whether a third variable moves both. Second, the p-value is not the probability that the null hypothesis is true. It is computed inside a world where the null is assumed true, so it cannot grade that assumption's probability. What it tells you is narrower and still useful: results this lopsided would be uncommon if the boring explanation held.

The chi square test of independence, step by step

Quick answer: lay the counts in a table with rows for one variable and columns for the other. Each cell's expected count is its row total times its column total divided by the grand total. Sum (O − E)² / E over all cells for the statistic, use df = (rows − 1)(columns − 1), and read the right-tailed p-value.

The expected-count formula encodes exactly what independence means. If row and column variables are independent, the share of observations falling in a column should be the same in every row, so each cell should hold its row's fair slice of the column total. When the real counts depart from those fair slices in a coordinated way — one row hogging a column, another starved of it — the contributions pile up and χ² grows. The test is symmetric: it does not matter which variable you call the row and which the column, and the statistic is identical either way round.

One design condition matters before any arithmetic: the observations must be independent of each other. One person counted once contributes one tally; one person counted in three cells, or patients clustered inside two clinics treated as many independent observations, breaks the logic of the test no matter how carefully the sums are done. Paired or repeated categorical data need a different test (McNemar's test is the paired 2 × 2 analogue). This calculator performs the arithmetic; whether your sampling earned the arithmetic is a question about the study, not the sums.

The chi square goodness of fit test

Quick answer: goodness of fit compares one observed list of category counts against one expected list. The statistic is the same sum, Σ (O − E)² / E, and the degrees of freedom are the number of categories minus one, provided the expected distribution was fixed before the data arrived.

The classic use is checking a claimed distribution: are dice landing evenly, do website sign-ups spread across the week the way last year's proportions say, does a sample's age mix match the census? A fair six-sided die rolled 120 times expects 20 per face; observed counts of 18, 22, 20, 19, 21, 20 give contributions of 0.200, 0.200, 0, 0.050, 0.050 and 0, totalling χ² = 0.500 on 5 degrees of freedom — a p-value around 0.992, about as consistent with fairness as data ever look. Paste those two lists into goodness-of-fit mode and the calculator reproduces the figure exactly, which makes it a good first check of the tool.

The degrees-of-freedom detail is the one place goodness of fit bites. If the expected distribution was estimated from the same data — fitting a normal distribution's mean and standard deviation from the sample, then testing the sample against that fitted curve — each estimated parameter costs an extra degree of freedom. Ignore that and the test becomes too forgiving. When the expected list is genuinely external (a census, a theory, last year's audited figures), k − 1 is correct, and that is the case this calculator's goodness-of-fit mode is built for. Comparing a sample against a fitted curve is also where the Normal Distribution Calculator becomes the natural companion tool.

Expected counts and the below-5 rule

Rule of thumb: the chi-square p-value is an approximation, and it holds up when expected counts are reasonably large. The traditional guidance, associated with W. G. Cochran's 1954 recommendations, is that no expected count should fall below 1 and no more than about a fifth of cells should fall below 5. This calculator checks every cell and warns you on the results panel the moment any expected count drops below 5.

Why does a small expectation break things? The p-value comes from a smooth continuous curve approximating a lumpy discrete reality. In a cell expecting 25, the possible counts cluster tightly enough that the curve fits well. In a cell expecting 1.5, the count can only be 0, 1, 2, 3 — coarse steps the smooth curve represents badly, and the error lands directly in the tail where the p-value lives. The statistic itself is still computed exactly; it is the translation from statistic to probability that degrades.

When the warning appears you have honest options. Combine sparse categories with neighbours when the merged category still means something (age bands 70–79 and 80+ becoming 70+, say). Collect more data if the study is still running. Or switch to an exact method that enumerates the possibilities instead of approximating them — Fisher's exact test for a 2 × 2 table is the standard route. What you should not do is report the approximated p-value with four-decimal confidence and hope nobody asks about the expected counts; reviewers ask, and the expected counts are printed beside every result on this page precisely so the question is easy to answer.

Degrees of freedom: where (r − 1)(c − 1) comes from

Quick answer: degrees of freedom count how many cell counts are free to vary once the totals are fixed. In an r × c table the row and column totals are set by the data's margins, and filling in any (r − 1)(c − 1) interior cells determines all the rest — so that product is the df.

Make it concrete with a 2 × 2 table whose row totals are 50 and 50 and whose column totals are 50 and 50. Choose the top-left cell freely — say 30 — and every other cell is forced: top-right must complete its row (20), bottom-left its column (20), bottom-right both (30). One free choice, one degree of freedom. A 3 × 4 table lets you choose 2 × 3 = 6 cells freely before the margins close the rest, hence df = 6. The chi-square distribution's shape depends on this number because more free cells means more independent squared pieces in the sum, which pushes the distribution right and spreads it out — the reason the critical value at 0.05 climbs from 3.841 at df = 1 to 18.307 at df = 10.

Degrees of freedom are also the detail most often dropped in write-ups, which makes results unverifiable: χ² = 4.000 is significant at df = 1 (p = 0.0455) and nowhere near significant at df = 6 (p = 0.677). Report the trio together — statistic, df, p — every time. If your statistic came from means rather than counts, the T-Test Calculator handles that family, and its df rules (n − 1 and friends) are the ones that apply there instead.

The chi square p value: the right tail and the gamma function

Quick answer: the chi square p value is the probability that a chi-square-distributed variable with your degrees of freedom would reach or exceed your statistic: p = P(χ² ≥ yours). Chi-square tests are always read from this right tail, because the statistic is never negative and only large values argue against the null.

Computing that tail is the one piece of real machinery on the page. The chi-square distribution is a gamma distribution in disguise — shape df/2, scale 2 — so its cumulative probability is the regularised lower incomplete gamma function: P(χ² ≤ x) = γ(df/2, x/2) / Γ(df/2). This calculator implements that function the way Numerical Recipes prescribes: a rapidly converging series when x is small relative to the shape, and a continued fraction for the upper tail when x is large, switching between the two where each is accurate. It is the same algorithm family statistical packages use, and the page's anchor values verify it: χ² = 3.841 at df = 1 returns p = 0.0500, χ² = 5.991 at df = 2 returns p = 0.0500, and χ² = 10 at df = 5 returns p = 0.0752.

Because the calculation is exact arithmetic on your statistic, the remaining question is always whether the statistic deserved trust — independent observations, adequate expected counts, categories defined before the data were peeked at. A precisely computed p-value from a test whose conditions failed is precise-looking and wrong, which is why the guide spends as much space on expected counts and design as on the gamma function. Variability measures sit upstream of many of these tests too: the Standard Deviation Calculator covers the spread calculations that feed the parametric side of the same analyses.

Critical values: when is chi-square significant?

The table gives, for each degrees of freedom, the χ² value that sits exactly on the boundary for the common significance levels: a statistic above the value in the α = 0.05 column has a p-value below 0.05. It is the same decision as comparing p with α, read from the other direction, and it doubles as a check on this calculator — enter any table value in lookup mode and you should get its α back.

dfα = 0.10α = 0.05α = 0.025α = 0.01α = 0.001
12.7063.8415.0246.63510.828
24.6055.9917.3789.21013.816
36.2517.8159.34811.34516.266
47.7799.48811.14313.27718.467
59.23611.07012.83315.08620.515
610.64512.59214.44916.81222.458
813.36215.50717.53520.09026.125
1015.98718.30720.48323.20929.588

Read the df = 1 row as the 2 × 2 workhorse: 3.841 is the number behind most textbook examples, and the worked example below lands just past it at 4.000. Notice the cost of stricter evidence down each column — at α = 0.001 a df = 1 statistic must reach 10.828 — and the steady rightward march across rows, which is the visual form of the degrees-of-freedom story above. If a value you need sits between table rows, lookup mode computes it exactly rather than asking you to interpolate.

Worked example: a 2 × 2 table, fully checked

The data: two clinics, 100 patients, outcome recovered or not. Clinic A: 30 recovered, 20 not. Clinic B: 20 recovered, 30 not. Each row totals 50, each column totals 50, grand total 100. The question the chi square test of independence answers: is recovery associated with clinic, or could this split plausibly arise if clinic made no difference?

Expected counts: every cell expects row total × column total ÷ grand total = 50 × 50 ÷ 100 = 25. Contributions: each cell is 5 away from expectation, so each contributes (5)² ÷ 25 = 1.000, and the four cells give χ² = 4.000. Degrees of freedom: (2 − 1)(2 − 1) = 1. P-value: the right tail beyond 4.000 at df = 1 is 0.0455 — just under the 0.05 line, so the result is labelled significant at the 5 percent level, and the pre-filled table in the calculator above reproduces every one of these figures for you to check.

Reading it honestly: the honest sentence is “recovery was associated with clinic in this sample (χ²(1, N = 100) = 4.000, p = 0.0455)”. The dishonest upgrade — “Clinic A causes better recovery” — does not follow. Perhaps Clinic A genuinely treats better; perhaps it receives younger patients; perhaps its nurses record recovery differently. The chi-square test cannot distinguish those stories, and p = 0.0455 sitting a hair under the threshold should make everyone more cautious, not less: a handful of patients reclassified would move it across the line. Report the effect size too — here the recovery rates are 60 percent versus 40 percent, a 20-point gap, which is the part of the result a decision-maker can actually weigh.

Common mistakes

Feeding the test percentages or averages. Chi-square arithmetic runs on counts. Percentages strip out the sample size the statistic depends on, and means belong to a different family of tests entirely. Counting the same observation twice. A respondent who appears in two cells, or before-and-after answers treated as independent tallies, inflates the statistic with information that is not there. Ignoring the expected-count warning. A p-value built on cells expecting 1 or 2 is an approximation outside its comfort zone; merge categories or use an exact test instead of quoting it.

Reading association as causation. The test's most expensive misreading, covered in the example above: significance licenses “associated”, never “caused”. Fishing through tables. Slice a dataset twenty ways and one slice will cross 0.05 by chance alone roughly once; a table chosen because it looked significant carries a p-value that no longer means what it claims. Dropping the degrees of freedom. “χ² = 4.000, p = 0.0455” is checkable; “χ² = 4.000, significant” is not, because the same statistic is unremarkable at higher df. Treating 0.05 as a cliff. p = 0.0455 and p = 0.0545 are near-identical evidence; describe borderline results as borderline, as the example does.

Honest limits: what this calculator does not do

This chi square calculator performs the test's arithmetic exactly and checks its expected counts, but it cannot check the things arithmetic cannot see. It does not verify that your observations are independent, that categories were defined before the data were examined, or that the sample represents the population you want to describe — a biased sample yields a beautifully precise answer about the wrong group. It does not run exact tests (Fisher's exact test for small 2 × 2 tables), paired tests (McNemar), or trend tests for ordered categories, each of which answers a nearby question better when its conditions apply. It does not adjust for multiple comparisons, and it does not compute effect sizes such as Cramér's V, which a complete report needs beside the p-value. Tables are capped at 5 × 5 and expected counts are capped by nothing but the warning system — the below-5 warning is information, not a lockout, because sometimes a flagged result is still the best available summary of sparse data. What the page does guarantee is the calculation itself: expected counts by the standard formula, the statistic by Pearson's sum, and the p-value by the regularised incomplete gamma function, verified against the published critical values tabulated above.

Sources and References

Source verification note: all seven sources above returned HTTP 200 to a direct check on 24 November 2026. Substitutions are disclosed: the Penn State STAT 500 chi-square pages originally considered could not be verified (the host returned no response to direct checks), the BMJ Statistics at Square One chi-squared chapter returned HTTP 403, and the Boston University School of Public Health chi-square module redirected to a generic homepage rather than the module — so the JMP Statistics Knowledge Portal and the two encyclopaedia references above are used instead. No source that could not be verified is cited.