Maths

Chi-Square Calculator

Run a chi-square goodness-of-fit test or test of independence, with χ², degrees of freedom and p-value.

By Nitin Raturi · Last reviewed

Your counts

How to use the Chi-Square Calculator

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

  1. Choose the test.
  2. Enter the observed counts, or the table.
  3. For goodness of fit, enter expected counts or percentages, or leave blank.
  4. Read χ², the degrees of freedom and the p-value.

Good to know

  • Each expected count should be at least 5 for the test to be reliable.

Test

Goodness of fit compares one row of counts with expected shares; independence checks a table.

How to fill it in

  • Goodness of fit: one line of counts.
  • Independence: a table, one row per line.

Example

Volunteer type by hours (OpenStax 11.6): χ² = 12.9909, p = 0.0113.

Observed counts

The counts you actually saw.

How to fill it in

  • Separate counts with spaces or commas; for a table put each row on its own line.

Example

Absences 15 12 9 9 15 against equal days: χ² = 3.0000, p = 0.5578.

Counts separated by spaces or commas.

Expected (goodness of fit)

Expected counts or percentages for each category; ignored for independence.

How to fill it in

  • Leave blank for equal shares; percentages are scaled to the observed total.

Example

66 119 340 60 15 against 10 16 55 11 8 percent: χ² = 29.6464, p = 0.000006.

Counts or percentages; blank for equal shares. Not used for independence.

Significance level (%)

The p-value below which you reject the null hypothesis.

How to fill it in

  • 5% is common.

Goodness-of-fit test

χ² = 3.0000, p = 0.5578

χ² = 3.0000 with 4 degrees of freedom gives p = 0.5578, not below α = 5%: do not reject the null hypothesis.

Degrees of freedom
4
Expected counts
12.00, 12.00, 12.00, 12.00, 12.00

Independent observations counted in categories. The chi-square approximation needs expected counts of about 5 or more in each cell.

How this calculator works

  1. Step 1ExpectedEFrom shares, or row × column ÷ total.
  2. Step 2StatisticΣ (O − E)² ÷ EHow far counts are from E.
  3. Step 3p-valueχ² tailWith the right degrees of freedom.

A chi-square test asks whether observed counts are close enough to the counts you would expect if the null hypothesis were true. Big gaps, relative to the expected counts, make χ² large.

For goodness of fit the expected counts come from the shares you give. For independence they come from the table’s row and column totals.

Worked example: OpenStax Example 11.2

Absences on five weekdays: 15, 12, 9, 9, 15
χ²
Σ (O − 12)² ÷ 12
  1. Expected per day60 ÷ 512
  2. Contributions9/12 + 0 + 9/12 + 9/12 + 9/123
  3. Degrees of freedom5 − 14
  4. p-value0.5578

OpenStax gives χ² = 3 and p = 0.5578: no evidence that absences depend on the day.

Read the result

  • Streaming services (11.3)p = 0.000006χ² = 29.6464: the region differs from the nation.
  • Volunteers (11.6)p = 0.0113χ² = 12.9909 on a 3 × 3 table.

A small p-value says the counts do not fit the expectation; it does not say which categories differ. Compare observed and expected counts for that.

Assumptions and limits

  • CountsUse frequencies, not percentages, for observed data.
  • Expected ≥ 5Small cells make the p-value unreliable.
  • IndependentEach observation counted once.
  • Upper tailChi-square tests are right-tailed.

Chi-square tests counts in categories. Means and test statistics have their own tools.

To compare two sample means, use the t-test calculator. The p-value calculator converts z or t statistics, and the sample size calculator plans how much data you need.

Common mistakes

  • Mistake: Entering percentages as observed values.

    Instead: Enter the counts themselves.

  • Mistake: Using rows − 1 for a table’s df.

    Instead: Use (rows − 1)(columns − 1).

Checking the method

A separate script recomputes each statistic in exact fractions and the tail with a closed form or numerical integration, reproducing OpenStax Examples 11.2, 11.3 and 11.6.

Read how we test our calculators, or browse more maths calculators.

Frequently asked questions

What is χ² for absences of 15, 12, 9, 9, 15?

3.0000 with 4 df, p = 0.5578 (OpenStax Example 11.2).

How do I test against percentages?

Enter them as expected values. OpenStax’s streaming example gives χ² = 29.6464, p = 0.000006.

How is a test of independence done?

Enter the table, one row per line. OpenStax Example 11.6 gives χ² = 12.9909, p = 0.0113.

How many degrees of freedom?

Goodness of fit: categories − 1. Independence: (rows − 1) × (columns − 1).

When is the test unreliable?

When many expected counts are below 5; the calculator warns you.

Sources and methodology

The formulas are standard time-value-of-money results. We check every figure against golden values worked out independently, by closed form and by month-by-month simulation; see the methodology.

Written and maintained by Nitin Raturi, a software engineer (about the author). Last reviewed 4 Nov 2026; next review due by . Found an error? Tell us.

Changelog

  • : Initial release.