Use this chi-square test calculator to run a chi-square test of independence on a contingency table of up to 5 × 5, or a goodness-of-fit test against expected counts. Enter your observed counts below and it returns the chi-square statistic, degrees of freedom and p-value, with the expected counts and every (O − E)²/E contribution shown.
A chi-square test calculator compares observed counts with the counts you would expect if the null hypothesis were true. It adds up (O − E)²/E over every cell to give χ², then turns χ² and the degrees of freedom into a p-value. A small p-value (below 0.05) means the data do not fit the null hypothesis, so you reject it.
Chi-Square Test Calculator
Test two categorical variables for independence in a contingency table, or test counts against expected counts — with the full expected-count and contribution tables, Yates correction and Cramer's V.
Enter whole counts (0 or more). Each row is one group of the first variable; each column is one group of the second variable.
Chi-square, df, p-value, expected counts, contributions, Yates correction and Cramer's V.
Try:
Reject H0 at α = 0.05
df = 1 · p-value = 0.0098 · N = 60 · smallest expected count 15.00
How it was worked out
Expected counts and contributions
Observed vs expected
A chi-square test calculator compares the counts you actually observe with the counts you would expect if the null hypothesis were true. It adds up (O − E)²/E over every cell or category to get the chi-square statistic, then converts it into a p-value using the chi-square distribution. If the p-value is below 0.05, reject the null hypothesis; otherwise, fail to reject it.
What is a chi-square test?
A chi-square test is a hypothesis test for categorical data — counts in groups, not measurements. It asks whether the counts you collected are consistent with what a hypothesis predicts. The calculator above gives the chi-square statistic (χ²), the degrees of freedom and the p-value, so you can judge that question in seconds. To understand the p-value itself, read what is a p-value?.
There are two kinds, and they answer different questions. A test of independence uses a contingency table: every observation falls into one row category and one column category, and the test asks whether the two variables are associated — for example, treatment group and outcome. A goodness-of-fit test compares one set of observed counts with a set of expected counts, for example testing whether a die lands on each face equally often. Choose the test before you look at the data, because the hypotheses and the degrees of freedom are different.
How to do a chi-square test
- State the hypotheses. For independence, H0 is that the two variables are independent (there is no association). For goodness of fit, H0 is that the observed counts follow the expected distribution.
- Collect the observed counts. Enter them in the calculator: a table of up to 5 × 5 for independence, or one count per category for goodness of fit. The test only works on counts — never on percentages or averages.
- Work out the expected counts. For independence, E = (row total × column total) ÷ grand total. For goodness of fit, E = total × the expected proportion for that category (or total ÷ number of categories when all outcomes are equally likely).
- Check the conditions. Observations must be independent, the data must be a random sample, and every expected count should be at least 5 — see the rule below.
- Calculate the statistic and the degrees of freedom. χ² = Σ (O − E)²/E. The degrees of freedom are (rows − 1) × (columns − 1) for independence and categories − 1 for goodness of fit. The chi-square distribution is a different curve from the t distribution, which the t-distribution calculator covers.
- Find the p-value and decide. The p-value is the area under the chi-square curve (with your degrees of freedom) to the right of your χ². If p is smaller than your significance level α (usually 0.05), reject H0; otherwise, fail to reject it. You can also turn a z-score into a p-value with the p-value calculator from z-score.
Worked example: test of independence (2 × 2)
A survey records 60 people by treatment (yes/no) and outcome (improved/not improved): [[10, 20], [20, 10]]. The row totals are 30 and 30, the column totals are 30 and 30, so every expected count is (30 × 30) ÷ 60 = 15. Each contribution is (10 − 15)² ÷ 15 = 1.667, giving χ² = 6.667 with df = (2 − 1) × (2 − 1) = 1 and p = 0.0098. Because p is below 0.05, reject H0: treatment and outcome are associated. The Yates-corrected value is χ² = 5.400 (p = 0.0201) and Cramér's V is 0.333, a medium-to-large association.
Worked example: goodness of fit
Sixty rolls of a die give counts [16, 18, 16, 10] across four faces, against an expected 15 each. The contributions are 0.067, 0.600, 0.067 and 1.667, so χ² = 2.400 with df = 4 − 1 = 3 and p = 0.4936. Because p is well above 0.05, fail to reject H0: the data are consistent with the expected distribution. A second example, the 2 × 3 table [[10, 15, 5], [20, 10, 15]], gives expected counts of 12, 10, 8 in row 1 and 18, 15, 12 in row 2, χ² ≈ 6.597, df = 2, p ≈ 0.0369 (reject at 0.05) and Cramér's V ≈ 0.297. If your data are measurements rather than counts, use the normal distribution calculator instead — the chi-square test only works on counts.
Chi-square test formula
The test statistic is χ² = Σ (O − E)²/E, where O is each observed count and E is the matching expected count. For a 2 × 2 table, the Yates correction subtracts 0.5 from each |O − E| before squaring: χ²Yates = Σ (|O − E| − 0.5)²/E. Cramér's V measures the strength of association in an independence test: V = √(χ² ÷ (N × (min(rows, columns) − 1))), ranging from 0 (no association) to 1 (perfect association).
| Degrees of freedom | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Critical value at α = 0.05 | 3.841 | 5.991 | 7.815 | 9.488 | 11.070 |
At the 5% level, χ² = 6.667 with 1 degree of freedom exceeds 3.841, matching the decision to reject, while χ² = 2.400 with 3 degrees of freedom is below 7.815, matching the decision to fail to reject. For a single proportion, the one-proportion z-test calculator is the right tool instead.
When is the chi-square test valid?
Three conditions matter. First, the data must be counts from a random sample, with observations independent of each other. Second, every expected count should be at least 5 — this is the expected-count rule. If some expected counts are below 5, combine categories where it makes sense, or use Fisher's exact test for a 2 × 2 table. Third, the categories must be mutually exclusive: each observation belongs in exactly one cell. Small samples are fine as long as the expected counts are large enough. The NIST/SEMATECH e-Handbook of Statistical Methods gives the chi-square critical values used here.
How to interpret the chi-square p-value and Cramér's V
The p-value is the probability of a chi-square statistic at least as large as yours if H0 were true. A small p-value means the data do not fit H0 — it is not the probability that H0 is true. Because the chi-square test is one-sided (it only looks at the right tail), there is no two-sided version to worry about, unlike a z test, where the critical z-value calculator gives the two-sided cut-offs. Cramér's V then tells you how strong the association is: about 0.1 is small, 0.3 is medium and 0.5 is large. Standardising a measurement is a different job — see how to calculate a z-score.
Chi-square test FAQs
What is the formula for a chi-square test?
The formula is χ² = Σ (O − E)²/E: for every cell or category, subtract the expected count E from the observed count O, square the difference, divide by E, and add the results together. The expected counts come from the null hypothesis — (row total × column total) ÷ grand total for a test of independence, or total × expected proportion for goodness of fit.
How do you find the p-value for a chi-square test?
Find the area under the chi-square distribution curve, with your degrees of freedom, to the right of your chi-square statistic. The calculator above does this for you. A larger χ² gives a smaller p-value, and a p-value below your significance level (usually 0.05) means you reject the null hypothesis.
When do you reject H0 in a chi-square test?
Reject H0 when the p-value is smaller than your significance level α, usually 0.05. Equivalently, reject H0 when the chi-square statistic is larger than the critical value for your degrees of freedom — for example, 3.841 with 1 degree of freedom at α = 0.05.
What is the difference between a chi-square test of independence and a goodness-of-fit test?
A test of independence uses a contingency table with two categorical variables and asks whether they are associated. A goodness-of-fit test uses one set of observed counts and asks whether they match a claimed or expected distribution. Independence has (rows − 1) × (columns − 1) degrees of freedom; goodness of fit has categories − 1.
What is Yates correction and when should I use it?
Yates correction is a continuity correction for 2 × 2 tables only: subtract 0.5 from each |O − E| before squaring, so χ²Yates = Σ (|O − E| − 0.5)²/E. It makes the test more conservative for small counts. Use it for a 2 × 2 test of independence; the calculator shows it whenever your table is 2 × 2.
What is Cramér's V?
Cramér's V is an effect-size measure for a chi-square test of independence, ranging from 0 (no association) to 1 (perfect association). Its formula is V = √(χ² ÷ (N × (min(rows, columns) − 1))). Roughly, 0.1 is a small association, 0.3 is medium and 0.5 is large. It does not apply to goodness-of-fit tests.
What is the expected count rule for a chi-square test?
Every expected count should be at least 5 for the chi-square approximation to be reliable. A common version allows up to 20% of expected counts below 5 as long as none is below 1, but the calculator here flags any expected count under 5 so you can decide. If the rule fails, combine categories or use an exact test.
Can I use a chi-square test with a small sample?
Yes, if the expected counts are still at least 5 — it is the expected counts that matter, not the sample size alone. With a very small sample the expected counts are usually too small, so the p-value cannot be trusted. In that case combine categories where it makes sense, or use Fisher's exact test for a 2 × 2 table.
Keep going: you can browse all the calculator tools on the tools page. The critical values and the expected-count rule used here follow the NIST/SEMATECH e-Handbook of Statistical Methods.
More Tools to Explore
Z-Score Calculator
Turn any value into a z-score and find its percentile and probability on the bell curve.
Try CalculatorNormal Distribution Calculator
Find probabilities, percentiles and critical values for any normal distribution.
Try CalculatorP-Value Calculator from Z-Score
Turn any z-score into a one- or two-tailed p-value — or work backwards from a p-value to its z-score.
Try CalculatorZ-Score to Percentile Converter
Convert a z-score to a percentile in a normal distribution. Enter your z-score to see the percentage of values below it.
Try CalculatorIQ Bell Curve Calculator
Convert an IQ score into a z-score, percentile and rarity on the bell curve.
Try CalculatorExplore All Statistical Tools
Browse all 43 free statistics tools in one place — no sign-up, instant results.
Browse All Tools