The Chi-Square Test on a 2x2 Table: A Worked Example

October 29, 2026

The chi-square test of independence asks whether two categorical variables are related, for example whether a treatment is associated with improvement, or whether a marketing email is associated with purchase. It compares the observed counts in a table with the counts you would expect if the variables were independent. A large difference gives a large chi-square statistic and a small p-value.

Suppose 100 patients are split into a treatment group and a control group of 50 each. In the treatment group, 30 improved and 20 did not; in the control group, 18 improved and 32 did not. Is the treatment related to improvement, or could the difference be chance?

Skip the math and get your answer instantly:

Open the Standard Deviation Calculator →

Step 1: Expected Counts

Row totals are 50 and 50, and column totals are 48 improved and 52 not improved, out of 100. If the variables were independent, the expected count in each cell = row total × column total ÷ grand total. For treatment and improved: 50 × 48 ÷ 100 = 24. For treatment and not improved: 50 × 52 ÷ 100 = 26. For control and improved: 24. For control and not improved: 26. The observed counts (30, 20, 18, 32) differ from the expected (24, 26, 24, 26) by +6, −6, −6, and +6.

Improved (observed)Not improved (observed)Total
Treatment302050
Control183250
Total4852100

Step 2: The Statistic

Chi-square = Σ (O − E)² ÷ E over all cells. Each cell contributes 6² ÷ E: 36 ÷ 24 = 1.5, 36 ÷ 26 = 1.385, 36 ÷ 24 = 1.5, and 36 ÷ 26 = 1.385. The sum is 5.77. For a 2x2 table, the degrees of freedom are (rows − 1) × (columns − 1) = 1. With 1 degree of freedom, the critical value for a 5% significance level is 3.84, and for 1% it is 6.63. Our statistic of 5.77 exceeds 3.84, so the result is significant at the 5% level. The p-value is about 0.016.

Software such as a spreadsheet's CHISQ.TEST function or a statistics package gives the exact p-value. Some analysts apply Yates' continuity correction for 2x2 tables, which would reduce the statistic slightly (to about 4.85, p = 0.028).

Step 3: Interpret

A p-value of 0.016 means that if treatment and improvement were unrelated, we would see a difference this large or larger only about 1.6% of the time. That is evidence of an association, with the treatment group improving at 60% versus 36% for the control, a difference of 24 percentage points. The test does not tell you the strength or the cause. Report the effect size: the risk difference (24 points), the relative risk (60 ÷ 36 = 1.67), or the odds ratio (30 × 32 ÷ (20 × 18) = 2.67). Randomized assignment supports a causal reading; observational data do not.

Assumptions and Cautions

The observations must be independent (each person counted once), the categories mutually exclusive, and expected counts should generally be at least 5 in every cell. For small samples or small expected counts, use Fisher's exact test. Large samples can make trivial differences statistically significant, so look at the effect size. The chi-square test says nothing about direction in larger tables unless you inspect the cells. Don't run many tests and report only the significant one without adjustment.

Frequently Asked Questions

What does a chi-square test of independence do?

It tests whether two categorical variables are associated by comparing observed and expected counts.

How do I find expected counts?

Row total times column total divided by the grand total.

What are the degrees of freedom for a 2x2 table?

One.

When should I use Fisher's exact test instead?

When sample sizes are small or expected counts are below about 5.

Does a significant result prove causation?

No. Only well-designed randomized experiments support causal conclusions.