Chi-Square Calculator
Paste a table of counts, or a column of observed counts next to expected frequencies, and choose the type of test. The result is the chi-square statistic, its p-value and the degrees of freedom, with a warning when the data are too sparse.
Related calculators
Created by the Reeliy Editorial Team. Last updated: Oct 19, 2026
What the calculator does
A chi-square (Χ²) test asks whether the counts you observed differ from the counts you would expect if some simple hypothesis were true. This calculator runs the two most common versions:
- Independence / Homogeneity. You supply a table of counts, with groups in rows and categories in columns. The null hypothesis is that the row a person falls in tells you nothing about the column, or equivalently that every group has the same distribution across the categories.
- Goodness-of-fit. You supply observed counts and the frequencies a model predicts. The null hypothesis is that the data come from that model, for example a die being fair.
The output has three lines: the Χ² statistic, the p-value and the degrees of freedom. A fourth line, WARNING, appears when the sample is too small for the chi-square approximation to be trustworthy.
How to enter your data
- Put one group per line and one category per column. Separate columns with spaces, commas or tabs, so a block copied from a spreadsheet pastes straight in.
- For a test of independence use whole-number counts, never percentages or means. Every line needs the same number of values, and the table needs at least two rows and two columns.
- For goodness-of-fit use exactly two columns: observed counts first, expected frequencies second. The frequencies must add up to 1, with a tolerance of 0.001, and the expected count for each row is its frequency times the total of the observed counts.
- Use a dot as the decimal mark. Do not leave blank lines or add a leading space to a line, because that is read as a missing value.
Swapping rows and columns does not change the result. Anything that is not a number is read as zero.
The formula
Χ² = Σ (O − E)² ÷ ESum over every cell: O is the observed count and E the expected count.
For a table of counts the expected value of a cell assumes rows and columns are unrelated:
E = (row total × column total) ÷ grand total
degrees of freedom = (rows − 1) × (columns − 1)For goodness-of-fit with k categories the degrees of freedom are k − 1.
The p-value is the probability of a Χ² at least as large as yours when the null hypothesis is true, taken from the upper tail of the chi-square distribution with those degrees of freedom. You can convert a statistic you already have with the chi-square to p-value calculator.
Worked example: test of independence
In a trial, 100 patients received a new treatment and 100 received a standard one. Of the first group 45 improved and 55 did not; of the second group 30 improved and 70 did not. Arrange the counts like this, and enter 45 55 on the first line and 30 70 on the second:
| Improved | Not improved | |
|---|---|---|
| New treatment | 45 | 55 |
| Standard treatment | 30 | 70 |
Row totals are 100 and 100, column totals are 75 and 125, and the grand total is 200. Every row total is 100, so the expected counts are 100 × 75 ÷ 200 = 37.5 and 100 × 125 ÷ 200 = 62.5 in each row.
Χ² = 7.5²/37.5 + 7.5²/62.5 + 7.5²/37.5 + 7.5²/62.5 = 1.5 + 0.9 + 1.5 + 0.9 = 4.80
There is (2 − 1) × (2 − 1) = 1 degree of freedom and the p-value is 0.0285. This is below 0.05, so at the 5% significance level the data are inconsistent with the two treatments having the same improvement rate.
A p-value says whether an association is detectable, not how large it is. A common effect size for a table is Cramér's V = √(Χ² ÷ (N × (min(rows, columns) − 1))), here √(4.8 ÷ 200) ≈ 0.155, a small to moderate association.
Worked example: goodness-of-fit
A die is rolled 120 times and the faces 1 to 6 come up 25, 17, 15, 23, 24 and 16 times. If the die is fair every face should appear 120 ÷ 6 = 20 times.
Χ² = (25−20)²/20 + (17−20)²/20 + (15−20)²/20 + (23−20)²/20 + (24−20)²/20 + (16−20)²/20 = 100/20 = 5.00
With six categories there are 5 degrees of freedom and the p-value is about 0.416, far above 0.05, so there is no evidence that the die is unfair. To run it in the calculator choose Goodness-of-fit and enter each count next to 0.1667 (1/6 rounded). The six frequencies add up to 1.0002, inside the allowed tolerance, and the tool reports Χ² ≈ 5.00 and p ≈ 0.416.
Critical values
If your Χ² is larger than the critical value for your degrees of freedom, the result is significant at that level. These are the standard upper-tail values:
| Degrees of freedom | α = 0.05 | α = 0.01 |
|---|---|---|
| 1 | 3.841 | 6.635 |
| 2 | 5.991 | 9.210 |
| 3 | 7.815 | 11.345 |
| 4 | 9.488 | 13.277 |
| 5 | 11.070 | 15.086 |
| 10 | 18.307 | 23.209 |
| 20 | 31.410 | 37.566 |
For other significance levels, the critical value calculator gives the cut-off directly.
Assumptions and warnings
The p-value comes from a smooth chi-square curve that only approximates the real distribution of the statistic, and the approximation is poor when counts are small. The usual guidance is that each cell of a 2 by 2 table should be at least 5 and, for larger tables, that no more than about a fifth of the cells should fall below 5.
- The tool shows More than 20% of cells with values less than 5 detected as soon as any observed count in a test of independence is below 5.
- If every observed count is at least 5 but some expected count is below 5, it shows Cell with expected frequency less than 5 detected.
- No warning is given for goodness-of-fit, so check the expected counts (frequency × total) yourself.
Observations must also be independent: the same person should not appear in several cells. When counts are small, an exact test such as Fisher's exact test is a better choice than chi-square.
Common mistakes
- Entering percentages. The test depends on sample size, so it needs the raw counts. Percentages from different group sizes give meaningless results.
- Frequencies that do not sum to 1. In goodness-of-fit, the second column holds proportions, not counts. Divide the model's counts by their total first.
- A zero row or column. A row or column that sums to zero makes the expected counts zero, which the calculator reports as an error. Remove it.
- Reading significance as importance. With a very large sample even a trivial difference gives a tiny p-value. Look at the size of the difference as well.
To check whether the traffic split of an A/B test matches the plan, the sample ratio mismatch calculator applies a chi-square goodness-of-fit check for you.
Frequently asked questions
What is the difference between a test of independence and a test of homogeneity?
The arithmetic is identical. A test of independence asks whether two categorical variables measured on one sample are associated. A test of homogeneity asks whether several separately sampled groups share the same distribution of a variable.
How do I calculate degrees of freedom for a chi-square test?
For a table, multiply (rows − 1) by (columns − 1). For a goodness-of-fit test, subtract one from the number of categories.
What counts as a significant p-value?
By convention a p-value below 0.05 is called significant, meaning data this extreme would occur less than 5% of the time if the null hypothesis were true. The threshold is a convention, and you should choose it before looking at the data.
Why does the tool say my expected frequencies must sum to 1?
In goodness-of-fit mode the second column is read as the share of the total expected in each category, so the shares must add up to 1 (a difference of up to 0.001 is tolerated).
References
- Pearson K. On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine. 1900;50(302):157-175.
- Agresti A. Categorical Data Analysis, 3rd ed. Wiley; 2013.
- Cochran WG. Some methods for strengthening the common χ² tests. Biometrics. 1954;10(4):417-451.
Cite this calculator and page
If you use this page in your work, you can cite it as:
Reeliy Editorial Team. (2026). Chi-Square Calculator. Reeliy. https://reeliy.com/calculators/chi-square-calculator“Chi-Square Calculator.” Reeliy, 2026, https://reeliy.com/calculators/chi-square-calculator.