Chi square calculator (2x2 contingency table)
Build your 2x2 contingency table and get χ², degrees of freedom, the p-value, Yates' correction and Cramér's V, plus the expected frequency of every cell. Free, live, no signup.
This is the general contingency table calculator: built for anyone holding two categorical variables who needs to know whether they are associated. It is the tool for a stats class, a survey cross-tab, a thesis chapter or two columns of a dataset you want to compare. That is exactly why the row and column labels are editable: the table is yours, not an A/B test in disguise. If what you actually have is an experiment with a control and a variation and you want to know which one won, use the A/B test significance calculator, which returns lift and a confidence interval. This page answers a simpler, broader question: is there an association between these two variables?
Expected frequencies (under independence)
| - | - |
|---|
The test compares the counts you observed with the counts you would expect if the two variables were independent. The p-value answers: if there were no association at all, how often would chance alone produce a table as lopsided as yours? Cramér's V measures the STRENGTH of the association (0 = none, 1 = total), which is a different question from significance.
How to use it
- Rename the rows and columns to match your categories (for example: smoker and non-smoker; passed and failed).
- Type the four observed counts. These are counts of cases, never percentages or averages.
- Pick the significance level you committed to before looking at the data (0.05 is the market default).
- Read the verdict, then χ², degrees of freedom, p-value and Cramér's V below it.
- Check the expected frequencies and each cell's contribution to see where the association came from.
How it works: the chi-square formula
The test measures the distance between what you observed and what independence would predict. First the expected frequency of each cell, then the sum of squared deviations:
Where O is the observed count, E the expected one and N the grand total. Dividing by E is what makes the weighting fair: a gap of 7 cases is enormous where you expected 10 and irrelevant where you expected 5,000. The p-value comes from the upper tail of the chi-square distribution at that number of degrees of freedom. Cramér's V is √(χ² / N) in a 2x2 table, and restates the result as a strength of association that does not inflate with sample size.
Worked example (reproduces the default output)
The table that loads by default: Group A recorded 45 yes and 55 no (100 total) and Group B recorded 30 yes and 70 no (100 total). The columns add up to 75 yes and 125 no, with N = 200.
The expected count of the first cell is 100 × 75 / 200 = 37.5; the cell beside it is 100 × 125 / 200 = 62.5. Because the row totals match, the second row has the same expected values. Every deviation is 7.5 cases, so the contributions come out to 56.25/37.5 = 1.5 in the yes columns and 56.25/62.5 = 0.9 in the no columns. Adding all four: χ² = 1.5 + 0.9 + 1.5 + 0.9 = 4.8000, on 1 degree of freedom, for a p-value of 0.0285.
Since 0.0285 is below 0.05, the association is significant at 95% confidence: the share of yes genuinely differs between the groups. With Yates' correction each deviation drops from 7.5 to 7.0 and χ² falls to 4.1813, giving a p-value of 0.0409: still significant at 95%, but by a visibly thinner margin. Cramér's V is √(4.8/200) = 0.1549, a weak association. Every one of those numbers is exactly what the tool displays when the page loads.
How to read it, and where it breaks
Chi-square detects association, not causation and not direction. It tells you Group A's distribution differs from Group B's, but not which is higher or by how much: you read that off the percentages in your own table. It also cannot tell a real association apart from a collection bias. If your survey pulled different profiles into each group, the association you found may belong to the bias rather than the phenomenon.
Three limits deserve attention. First, sample size: with a very large N almost everything turns significant, which is precisely why the tool shows Cramér's V next to the p-value. Second, low expected frequencies: the rule of thumb wants every expected count above 5, and the calculator warns you when that fails, because below that threshold the approximation distorts and Fisher's exact test is the correct call. Third, independence of observations: each case must land in exactly one cell. Measuring the same person before and after breaks that assumption, and McNemar's test is the right one instead.
Worth noting that chi-square is the same engine behind the SRM checker, which compares an observed traffic split against the expected one. Sibling math, different question.
Good practice before you report the result
- Always report all three together: χ², degrees of freedom and p-value, formatted as χ²(1) = 4.80, p = .029.
- Publish the effect size. A p-value on its own says nothing about practical relevance.
- Feed the table raw counts. Converting to percentages first inflates or deflates χ² meaninglessly.
- Fix your significance level before seeing the data, never after glancing at the p-value.
- If any expected count falls below 5, say so in your write-up and prefer Fisher's exact test.
Frequently asked questions
- What does a chi-square test actually answer?
- It answers whether two categorical variables are associated or independent. In plain terms: is the difference between the rows of my table too large to be chance alone? The test compares the counts you observed against the counts you would expect if there were no association at all, and boils that distance down to a single number, the χ².
- How do I calculate the expected frequency of each cell?
- Multiply that cell's row total by its column total and divide by the grand total. If the row adds up to 100, the column adds up to 75 and the grand total is 200, the expected count is 100 x 75 / 200 = 37.5. That is the count you would see if the two variables were perfectly independent while keeping the marginal totals you actually observed.
- How many degrees of freedom does a 2x2 table have?
- One. The general rule is (rows minus 1) times (columns minus 1), so a 2x2 table gives (2-1) x (2-1) = 1. It means that once the row and column totals are fixed, knowing a single cell is enough to deduce the other three. With 1 degree of freedom, the critical χ² value at 95% confidence is 3.841.
- Should I use Yates' correction?
- It exists because chi-square is a continuous distribution being used to approximate discrete counts, and that approximation tends to overstate significance in small 2x2 tables. Yates subtracts 0.5 from each absolute difference before squaring, which makes the test more conservative. With large samples the difference is negligible. With small counts, many statisticians skip the correction and go straight to Fisher's exact test.
- What is Cramér's V and why is it shown here?
- It is the effect size: it measures the strength of the association on a 0 (none) to 1 (total) scale. You need it because χ² grows with sample size, so with 200,000 rows even a trivial difference turns statistically significant. The p-value tells you whether the association exists; Cramér's V tells you whether it matters. As a rough 2x2 benchmark: around 0.1 is weak, 0.3 moderate, 0.5 strong.
- Can I use this to analyse an A/B test?
- It works mathematically, but it is not the right tool for the job. In an A/B test you want the business verdict: which version won, by how much, and with what confidence interval. Chi-square only returns association yes or no, with no direction and no lift. For experiments use the significance calculator; keep this one for research, survey and coursework contingency tables.
Keep going
Want to understand the p-value itself, without a contingency table? The p-value calculator opens the number up. If your case is an experiment rather than research, start with the significance calculator. The underlying concept lives in the guide on statistical significance in A/B testing.