Chi Square Calculator: χ², p Value & Expected Counts

Chi square calculator with steps. Get the χ² statistic, degrees of freedom, p value, and the expected frequency for every cell, for goodness of fit or independence.

Chi Square Calculator

Chi square compares what you observed with what you would expect: χ² = Σ(O − E)² ÷ E. Pick your test, enter your counts, and the calculator shows the expected frequencies, the chi square statistic, degrees of freedom, and the p value with every step.

Enter the counts for each combination. Use the buttons to change the table size.

The Chi Square Calculator helps you perform the chi square test instantly using your observed and expected values. Whether you’re checking relationships between categorical variables or testing goodness of fit, this chi square test calculator gives you the chi square statistic, p value, and detailed step-by-step calculations.

This tool is perfect for students, researchers, data analysts, and anyone needing a fast way to calculate p value from chi square without solving formulas manually.

How to Use the Chi Square Calculator

Our Chi-Square Calculator makes the entire χ² test simple and fast. Just follow these steps:

Step 1: Choose Your Test Type

Select the chi-square test you want to run:

Chi-Square Goodness of Fit Test

Use when you want to compare:

  • one set of observed values
    vs.
  • one set of expected values

Example: expected equal distribution (25%, 25%, 25%, 25%).

Chi-Square Test of Independence (Contingency Table)

Use when comparing two categorical variables in a table format.

Example: Gender vs. Product Preference.

Step 2: Enter the Observed Values (O)

  • For goodness of fit, enter values in a single row.
  • For independence test, enter values into the contingency table (2×2, 3×3, 4×4, etc.).

Make sure all values are positive counts (no decimals).

Step 3: Enter the Expected Values (E)

(Only required for goodness of fit)

You may:

  • Enter your own expected values
    OR
  • Leave blank and our calculator computes equal expected frequencies automatically.

Step 4: Run the Calculation

Click Calculate Chi Square.

The tool instantly provides:

Chi Square Statistic (χ²)

Measures how different the observed counts are from the expected counts.

Degrees of Freedom (df)

Automatically computed as:

  • n – 1 for goodness of fit
  • (rows – 1) × (columns – 1) for independence test

p Value

Shows whether results are statistically significant.

Step 5: Interpret Your Results

Your results page will show:

✔️ If p-value < 0.05

There is a significant difference or association.
The categories are not independent.

✔️ If p-value ≥ 0.05

There is no significant difference.
The categories may be independent.

If you’re unsure how to calculate chi square, this tool simplifies everything.

What Is a Chi Square Test?

A chi square test (χ² test) is a statistical method used to determine whether there is a significant relationship between categorical variables or whether the observed frequencies in a dataset differ from the expected frequencies.

It is widely used in:

  • Research & experiments
  • Market surveys
  • Social sciences
  • Medical studies
  • A/B testing
  • Genetics
  • Data analytics

The chi square test helps answer questions like:

  • Are two groups related?
  • Is a treatment effective?
  • Does a sample match an expected distribution?

The results tell you whether any difference is due to random chance or represents a statistically significant pattern.

Types of Chi Square Tests

Types of Chi Square Tests

Our chi square test calculator supports all major chi square tests:

1. Chi-Square Test of Independence

Used to check if two categorical variables are related.
Example: Is gender associated with product preference?

2. Chi-Square Goodness-of-Fit Test

Used to check whether the observed data fits an expected distribution.
Example: Do dice rolls follow a uniform distribution?

3. Chi-Square Test of Homogeneity

Used to compare distributions across multiple populations.
Example: Do different regions have similar buying patterns?

How the Chi Square Test Works

The test compares two things:

  1. Observed values (O) → The actual data you collected
  2. Expected values (E) → The values you would expect if there was no relationship

Then the formula calculates how far O differs from E.

If the difference is large → significant relationship
If the difference is small → no significant relationship

Chi Square Formula

The core formula for calculating chi square​χ2=(OE)2E\chi^2 = \sum \frac{(O – E)^2}{E}

If:

  • χ² is large → Significant difference (reject null hypothesis)
  • χ² is small → Data fits expected pattern (fail to reject null)

This formula is used in the chi square statistic calculator built into this tool.

How the Chi Square Formula Works

How the Chi Square Formula Works

For each category:

  1. Subtract expected from observed → (O – E)
  2. Square the result → (O – E)²
  3. Divide by expected → (O – E)² / E
  4. Add everything together → Σ

This final value is your chi square statistic.

How to Calculate Expected Frequency in Chi Square

The expected frequency is what each cell would hold if the two variables had no relationship at all. Everything else in the test compares against it.

Expected frequency formula for a contingency table:

E = (Row total × Column total) ÷ Grand total

Say a table has a row total of 128, a column total of 96, and a grand total of 188. The expected count for that cell is (128 × 96) ÷ 188 = 65.36.

Expected frequency formula for goodness of fit:

E = Total ÷ Number of categories

With 60 students choosing between 4 topics, the expected count is 60 ÷ 4 = 15 per topic, assuming an equal split. If you have a different theory about the split, enter your own expected values instead.

One rule to watch: every expected count should be 5 or more. Below that, the chi square approximation breaks down and the p value stops being trustworthy. Combining small categories usually fixes it.

How to Calculate the Expected Value in Chi Square (Worked Example)

Numbers make this click faster than formulas. Suppose you survey 200 people about a product and split them by gender. Men who said yes total a row of 128, and the yes column totals 96, out of 188 responses overall. The expected count for men who said yes is:

E = (128 × 96) ÷ 188 = 65.36

You repeat that for every cell, always using its own row total times its own column total, divided by the grand total. Once you have all four expected counts, you compare each observed count against its expected count using the chi square formula. For a goodness of fit test the logic is simpler still: if you expect an even split, just divide the total by the number of categories. Sixty students across four topics gives 60 ÷ 4 = 15 expected per topic.

How Do You Find the P Value From Chi Square?

The p value tells you whether your chi square result means anything or whether it is just noise. You need two things to find it: your chi square statistic and your degrees of freedom. Feed both into a chi square distribution table or the calculator above, and you get the probability that a gap this large happened by pure chance.

Here is the plain reading. A small chi square value sits near the middle of the distribution, so its p value is high and your data matches expectation. A large chi square value sits far out in the tail, so its p value is low and something real is going on.

P valueCompared to α = 0.05What it means
p < 0.01Well belowStrong evidence of a relationship. Reject the null hypothesis.
p < 0.05BelowStatistically significant. The variables are likely related.
p = 0.05 to 0.10BorderlineWeak or no evidence. Treat with caution.
p > 0.05AboveNot significant. No real difference from expected.

Worked example. Say you run a chi square test and get χ² = 4.00 with 1 degree of freedom. Looking that up gives a p value of about 0.0455. Since 0.0455 is below 0.05, the result is significant and you reject the null hypothesis. Change nothing but the degrees of freedom to 3, and the same χ² = 4.00 gives a p value near 0.26, which is not significant. The degrees of freedom matter as much as the statistic itself.

To calculate the p value by hand you would need the chi square cumulative distribution, which involves the gamma function and is not practical on paper. A p value calculator or the tool on this page handles that math for you in one click.

How to Calculate Chi Square (Manually)

  1. Create a table for observed and expected frequencies
  2. Apply the chi square formula
  3. Find degrees of freedom:
    • Goodness-of-fit: df = categories − 1
    • Independence test: df = (rows − 1)(columns − 1)
  4. Use a chi square distribution table to calculate the p value

Or simply use our chi square calculator to avoid manual work.

Chi Square Test Example

These examples help users understand how the chi square test works in real life situations.

Example : Chi Square Goodness of Fit Test

Scenario

A teacher believes students choose between four project topics equally.
She records choices from 60 students:

TopicObserved (O)
A18
B12
C20
D10

Step 1: Expected Values (E)

If choices are equal:E=604=15E = \frac{60}{4} = 15

So expected = 15 for each topic.

Step 2: Apply Chi Square Formula

χ2=(OE)2E\chi^2 = \sum \frac{(O – E)^2}{E}

Now calculate each category:

TopicOE(O−E)²/E
A18150.6
B12150.6
C20151.67
D10151.67

Step 3: Chi Square Statistic

χ2=0.6+0.6+1.67+1.67=4.54\chi^2 = 0.6 + 0.6 + 1.67 + 1.67 = 4.54

Step 4: Degrees of Freedom

df=n1=41=3df = n – 1 = 4 – 1 = 3

Step 5: Interpretation

Using a chi square table or calculator:

  • χ² = 4.54
  • df = 3
  • p-value ≈ 0.21

Conclusion

Since p > 0.05, there is no significant difference.
Students do not prefer topics differently, distribution is close to equal.

Example: Chi Square Test of Independence (2×2)

Scenario

A shop wants to know if gender is related to product choice. They record 100 customers:

Product AProduct BRow total
Men203050
Women302050
Column total5050100

Step 1: Expected counts. Every cell has the same expected value here because both rows and both columns total 50: E = (50 × 50) ÷ 100 = 25 for each of the four cells.

Step 2: Apply the formula to each cell. Each cell contributes (O − E)² ÷ E. For every cell that is (difference of 5) squared over 25, which is 25 ÷ 25 = 1. Four cells each contribute 1.

Step 3: Chi square statistic. χ² = 1 + 1 + 1 + 1 = 4.00

Step 4: Degrees of freedom. df = (2 − 1) × (2 − 1) = 1

Step 5: Interpretation. With χ² = 4.00 and df = 1, the p value is 0.0455. Since that is below 0.05, the result is significant. Gender and product choice are related in this sample.

Notice the contrast with the goodness of fit example above, where p was 0.21 and nothing was significant. Same test family, opposite conclusion, and the p value is what tells them apart.

Example: Chi Square in Genetics (9:3:3:1 Ratio)

Biology students hit this one constantly. A dihybrid cross predicts offspring in a 9:3:3:1 ratio. You observe 315, 101, 108, and 32 across the four groups, 556 total. Do the results fit the expected ratio?

Expected counts come from splitting 556 by the 9:3:3:1 proportions: 312.75, 104.25, 104.25, and 34.75.

GroupObservedExpected(O − E)² ÷ E
9 part315312.750.016
3 part101104.250.101
3 part108104.250.135
1 part3234.750.218
Total (χ²)0.47

With χ² = 0.47 and df = 3 (four groups minus one), the p value is 0.93. That is far above 0.05, so the observed counts fit the 9:3:3:1 prediction beautifully. In genetics terms, the cross behaved exactly as Mendelian inheritance predicts.

Try these next

Frequently Asked Questions (FAQs)

How to calculate chi square?

To calculate chi square (χ²), subtract each observed value from the expected value, square the difference, divide by the expected value, and sum all results.
Formula:
χ² = Σ (O − E)² / E
Your chi square value shows how much the observed data differs from expected outcomes.

How to calculate p value from or for chi square?

Once you have the chi square statistic and the degrees of freedom (df), you can calculate the p value using a chi square distribution table or any online tool.
The p-value shows the probability that your observed differences could occur by chance.

How to calculate chi square in Excel?

You can calculate chi square in Excel using built-in functions:
1: CHISQ.TEST(observed_range, expected_range) → returns p-value
2: CHISQ.INV.RT(p, df) → returns chi square value
First prepare your observed and expected frequency tables, then apply the formula.

What is a Chi Square Test used for?

A Chi Square Test is used to check whether there is a significant relationship between categorical variables.

Is chi-square negative?

No, chi square values cannot be negative.
Because χ² is calculated from squared differences (O − E)², the result is always zero or positive. A value of zero means your observed and expected values match perfectly.

  • Parker Rowland

    Former Math Teacher

    Parker Rowland is a Former math teacher, author, and ed tech enthusiast focused on clear math explanations, practical problem solving & effective learning.

  • Yulduz Zaripova

    Data & Analytics Professional · MIT

    Yulduz Zaripova is a New York-based professional specializing in data analytics, financial engineering, and applied mathematics.