Chi-Square Calculator

Run a chi-square goodness-of-fit test or a test of independence.

Chi-Square Calculator tool

Test

For example 25, 50, 25 or 0.25, 0.5, 0.25

One row per line; separate the counts in a row with spaces or commas

—
Chi-square (χ²)
—
Degrees of freedom
—
p-value
—
Result

About the Chi-Square Calculator

Is a die fair? Does preference for a product depend on age group? Questions about counts in categories are answered with the chi-square test. This chi square calculator runs the goodness-of-fit test for one row of observed counts and the test of independence for a contingency table, showing the expected count for every cell, each cell's contribution, the degrees of freedom and the p-value. For a 2 × 2 table there is one degree of freedom, and a statistic above about 3.84 is significant at the 5 percent level. The test assumes expected counts of at least about five in each cell, and the calculator warns when that is not met.

The statistic is χ² = Σ (O − E)² ÷ E, summed over every cell, where O is an observed count and E the expected count. For goodness of fit, the expected counts come from your proportions, or are equal if you leave them blank, and the degrees of freedom are the number of categories minus 1. For independence, each expected count is row total × column total ÷ grand total, and the degrees of freedom are (rows − 1)(columns − 1). The p-value is the upper tail of the chi-square distribution.

Example: rolling a three-sided spinner 100 times gives 50, 30 and 20, against an expected 33.3 each. χ² = 14 with 2 degrees of freedom, so p ≈ 0.000912, strong evidence the spinner is unfair. In a 2 × 2 table of 20, 30 / 30, 20, every expected count is 25, χ² = 4 with 1 degree of freedom and p ≈ 0.0455, significant at the 5% level; with Yates' continuity correction χ² = 3.24 and p ≈ 0.0719.

The test needs counts, not percentages, and expected counts of about 5 or more in each cell. For other test statistics see the p-value calculator; for proportions, the confidence interval calculator; and for comparing means, the t-test calculator.

How to use the Chi-Square Calculator

  1. Choose the testGoodness of fit for one row of counts, or independence for a table.
  2. Enter the observed countsType counts separated by commas; for a table, one row per line.
  3. Add expected values if neededFor goodness of fit, enter expected counts or proportions, or leave blank for equal.
  4. Read the resultSee χ², degrees of freedom, the p-value and the expected counts.

Chi-Square Calculator features

  • Goodness-of-fit test
  • Test of independence for any r × c table
  • Expected counts and cell contributions
  • Yates' continuity correction for 2 × 2 tables
  • Exact p-value from the chi-square distribution
  • Critical value and verdict at your significance level
  • Warns when expected counts are small

Common uses

  • Survey cross-tabulations
  • Genetics ratios such as 9:3:3:1
  • Checking whether dice or games are fair
  • Marketing tests across customer groups
  • Statistics coursework

Chi-square tests in practice: fair dice, Mendel's peas and survey tables

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

The chi-square test compares counts you observed with counts you would expect if a particular idea were true. It answers questions such as whether a die is fair, whether a genetic ratio holds or whether two categories in a survey are related. This guide works through a die-rolling example and Gregor Mendel's famous pea experiment, explains the test of independence for tables and covers the rules that keep results valid.

Observed versus expected

The chi-square statistic adds up, for each category, the squared difference between observed and expected counts divided by the expected count. Large differences give a large statistic and a small p-value, suggesting the observed pattern does not fit the expectation. Small differences give a small statistic, consistent with chance variation.

A worked example: is the die fair?

A die is rolled 60 times, giving 8 ones, 11 twos, 9 threes, 14 fours, 7 fives and 11 sixes. A fair die would give 10 of each. The chi-square statistic is (8 − 10)²/10 + (11 − 10)²/10 + … = 3.2, with 5 degrees of freedom. That value is well below the 5% critical value of about 11.07, so the result is entirely consistent with a fair die.

Small differences such as 7 fives and 14 fours look uneven, but with only 60 rolls, such variation is normal. Detecting a slightly biased die would need many more rolls.

Mendel's peas

In the 1860s, Gregor Mendel crossed pea plants and predicted a 3:1 ratio of round to wrinkled seeds in the second generation. He counted 5,474 round and 1,850 wrinkled seeds, out of 7,324. The expected counts under a 3:1 ratio are 5,493 and 1,831, giving a chi-square statistic of only about 0.26. The fit is excellent, which supported his theory of inheritance.

Tests of independence

For tables of two categorical variables, such as age group and preferred shopping method, the chi-square test of independence checks whether the variables are related. Expected counts come from the row and column totals, assuming no relationship. A significant result suggests the preference differs between age groups, though it does not say which groups differ or why.

Expected counts must not be too small

The test relies on an approximation that works poorly when expected counts are small. A common rule is that every expected count should be at least 5. If some are smaller, combine categories that make sense together, collect more data, or use an exact test such as Fisher's exact test for small two-by-two tables.

Degrees of freedom

Degrees of freedom depend on the number of categories. For a goodness-of-fit test, they equal the number of categories minus one, minus any parameters estimated from the data. For a table, they are (rows − 1) × (columns − 1). Using the wrong degrees of freedom gives the wrong p-value, so check them carefully.

Counts, not percentages

The chi-square test must be calculated from actual counts. Using percentages, or averages, gives meaningless results, because the test's logic depends on the number of observations. If data has been summarised as percentages, convert it back into counts using the sample size before testing.

Common mistakes

  • Running the test on percentages instead of counts.
  • Ignoring expected counts below 5.
  • Using the wrong degrees of freedom.
  • Reading a significant result as proof of cause.

Related tools

For the p-value of any chi-square statistic, use P-Value Calculator. For probabilities, try Probability Calculator, and for comparing means, T-Test Calculator.

Chi-square in spreadsheets

Excel and Google Sheets provide =CHISQ.TEST(actual_range, expected_range), which returns the p-value directly for a goodness-of-fit or independence test once you have built the table of expected counts. =CHISQ.DIST.RT(statistic, degrees_of_freedom) turns a calculated chi-square statistic into a p-value. Building the expected table yourself is a good check that you understand what the test compares.

How strong is the relationship?

A significant chi-square test says that two categorical variables are related, but not how strongly. Cramér's V, calculated from the chi-square statistic, the sample size and the table's dimensions, measures the strength on a scale from 0 to 1. With very large samples, even weak relationships become significant, so reporting an effect size such as Cramér's V gives a fuller picture.

Planning a survey table

If you plan to analyse survey answers with a chi-square test, think about the table before collecting data. Too many categories spread responses thinly and produce small expected counts. Grouping answers sensibly in advance, such as combining rarely chosen options, keeps the test valid and the results easier to explain.

Which cells drive the result?

A significant test of independence does not say where the relationship lies. Looking at each cell's contribution to the chi-square statistic, or at standardised residuals, shows which combinations have far more or fewer observations than expected. In a survey table, that might reveal that one age group strongly prefers online shopping, which is the finding worth reporting.

Limits

Results follow the standard chi-square approximation; for small expected counts, exact methods are more reliable.

Frequently asked questions

What is a chi-square test?

A test for count data that measures how far observed frequencies are from the frequencies expected under a hypothesis. Large values of χ² suggest the observed pattern is unlikely to be due to chance.

How do I calculate chi-square?

For each cell, subtract the expected count from the observed count, square it and divide by the expected count. Add these up: χ² = Σ(O − E)² ÷ E.

How are degrees of freedom found?

For goodness of fit, the number of categories minus 1. For a contingency table, (rows − 1) × (columns − 1). A 3 × 4 table has 2 × 3 = 6 degrees of freedom.

How do I calculate expected counts for a contingency table?

Multiply the cell's row total by its column total and divide by the grand total. That is the count you would expect if the two variables were independent.

What does the p-value mean in a chi-square test?

The probability of getting a χ² at least this large if the null hypothesis were true. A p-value below 0.05 is usually taken as evidence of a real difference or association.

When should I use Yates' correction?

Some textbooks apply it to 2 × 2 tables, especially with small counts, to make the test more conservative. Many statisticians now prefer no correction, or Fisher's exact test for small samples.

What if expected counts are less than 5?

The chi-square approximation becomes unreliable. Combine categories, collect more data, or use an exact test such as Fisher's exact test for 2 × 2 tables. The calculator warns you when this happens.