# Two Proportion Z-Test: Formula and Worked Example

The 2 sample z test proportions compares the success rates of two independent groups to see whether the difference is real or just sampling noise. You pool the two samples into one combined proportion, build a standard error from it, and divide the difference in proportions by that standard error. This article gives you the formula and a complete worked example with every number shown.

## Quick Answer

- The 2 sample z test proportions checks whether two population proportions differ, using $z = (p_1 - p_2) / SE$.
- The standard error uses a pooled proportion: $SE = \sqrt{p_{pool}(1-p_{pool})(1/n_1 + 1/n_2)}$.
- The pooled proportion is total successes divided by total observations across both groups.
- A large absolute z value means the observed gap is unlikely under the null hypothesis of equal proportions.
- The test assumes independent samples, at least about 5 successes and 5 failures in each group, and a large-sample normal approximation.

## The Formula

The test statistic for comparing two independent proportions is:

$$z = \frac{p_1 - p_2}{\sqrt{p_{pool}(1 - p_{pool})\left(\frac{1}{n_1} + \frac{1}{n_2}\right)}}$$

Each symbol means the following.

| Symbol | Meaning |
|---|---|
| $p_1$ | Sample proportion in group 1, equal to $x_1 / n_1$ |
| $p_2$ | Sample proportion in group 2, equal to $x_2 / n_2$ |
| $x_1, x_2$ | Number of successes in each group |
| $n_1, n_2$ | Sample size of each group |
| $p_{pool}$ | Pooled proportion, equal to $(x_1 + x_2) / (n_1 + n_2)$ |
| $SE$ | Standard error of the difference in proportions |

The pooled proportion is the key idea. Under the null hypothesis the two groups share one true proportion, so you estimate it from all the data combined. That single estimate feeds the standard error. If you want a refresher on what a proportion is and how to compute one, see [What Is a Proportion? Definition, Formula and Examples](/blog/data-analysis/what-is-a-proportion).

The hypotheses are:

$$H_0: p_1 = p_2 \qquad H_a: p_1 \neq p_2$$

For a one-sided test you replace $H_a$ with $p_1 > p_2$ or $p_1 < p_2$ and use a single tail when you find the p-value.

## How to Calculate It Step by Step

1. State the null and alternative hypotheses. For a two-sided test, $H_0: p_1 = p_2$ and $H_a: p_1 \neq p_2$.
2. Compute each sample proportion: $p_1 = x_1 / n_1$ and $p_2 = x_2 / n_2$.
3. Compute the pooled proportion: $p_{pool} = (x_1 + x_2) / (n_1 + n_2)$.
4. Compute the standard error: $SE = \sqrt{p_{pool}(1 - p_{pool})(1/n_1 + 1/n_2)}$.
5. Compute the z statistic: $z = (p_1 - p_2) / SE$.
6. Find the p-value from the standard normal distribution. For a two-sided test, $p = 2 \times (1 - \Phi(|z|))$, where $\Phi$ is the standard normal cumulative distribution function.
7. Compare the p-value to your significance level, often 0.05, and decide whether to reject $H_0$.

If you need help turning a z value into a probability, the guide on [how to find the critical z value](/blog/data-analysis/how-to-find-critical-z-value) walks through the table lookup.

## Worked Example

A survey compares success proportions in two independent groups. Group 1 has 100 respondents with 40 successes. Group 2 has 120 respondents with 60 successes.

| Group | n | Successes |
|---|---|---|
| Group 1 | 100 | 40 |
| Group 2 | 120 | 60 |

**Step 1. Sample proportions.**

$$p_1 = 40 / 100 = 0.4000$$
$$p_2 = 60 / 120 = 0.5000$$

**Step 2. Pooled proportion.**

$$p_{pool} = (40 + 60) / (100 + 120) = 0.4545$$

**Step 3. Standard error.**

$$SE = \sqrt{0.4545 \times (1 - 0.4545) \times (1/100 + 1/120)} = 0.0674$$

**Step 4. Z statistic.**

$$z = (0.4000 - 0.5000) / 0.0674 = -1.4832$$

**Step 5. Two-sided p-value.**

$$p = 2 \times (1 - \Phi(|-1.4832|)) = 0.1380$$

The observed difference is 10 percentage points, and the test returns $z = -1.4832$ with $p = 0.1380$.

## How to Interpret the Result

The p-value of 0.1380 is the probability of seeing a difference at least this large if the two population proportions were truly equal. At the common 0.05 significance level, 0.1380 is larger, so you fail to reject the null hypothesis. The data do not provide enough evidence to conclude the two groups differ.

The negative sign on z simply reflects direction. Group 1 had the lower proportion, so $p_1 - p_2$ is negative. The magnitude, 1.4832, is what drives the p-value. A z of about 1.96 corresponds to a two-sided p-value of 0.05, so this result sits inside the non-rejection region.

Failing to reject is not proof that the proportions are equal. It means the sample is consistent with equal proportions. A larger sample might detect a real difference of this size. To understand how z values map to percentiles, see [Z-Scores and Percentiles: How They Relate and How to Convert](/blog/data-analysis/z-scores-and-percentiles).

## Doing It in Software (Excel, R or Python)

In Excel, you can compute each step with plain formulas. Use `=40/100` for $p_1$, `=(40+60)/(100+120)` for the pooled proportion, `=SQRT(p_pool*(1-p_pool)*(1/100+1/120))` for the standard error, and `=2*(1-NORM.S.DIST(ABS(z),TRUE))` for the two-sided p-value. Replace the cell references with your own.

In Python, the calculation is short:

```python
from scipy import stats
import math
n1, x1 = 100, 40
n2, x2 = 120, 60
p1, p2 = x1/n1, x2/n2
p_pool = (x1+x2)/(n1+n2)
se = math.sqrt(p_pool*(1-p_pool)*(1/n1+1/n2))
z = (p1-p2)/se
p = 2*(1-stats.norm.cdf(abs(z)))
print(f"z = {z:.4f}, p-value = {p:.4f}")
```

Output:

```
z = -1.4832, p-value = 0.1380
```

In R, `prop.test(c(40, 60), c(100, 120), correct = FALSE)` runs the test and reports a chi-squared statistic, which equals $z^2$ for the two-sided case. The square root of that statistic matches the z value here.

## Common Mistakes

- **Using unpooled standard errors for the hypothesis test.** The pooled proportion belongs in the test statistic because the null assumes equal proportions. Use the unpooled version only for confidence intervals.
- **Confusing the test with a confidence interval.** The z test answers whether a difference exists. A confidence interval estimates its size. They use different standard errors.
- **Ignoring the success and failure counts.** The normal approximation needs roughly 5 or more successes and 5 or more failures in each group. With rare events, use an exact method instead.
- **Treating paired data as independent.** If the same people appear in both groups, the samples are dependent and this test does not apply. Use a test for paired proportions.
- **Reading a one-sided p-value as two-sided.** Double-check which alternative you stated. A one-sided p-value is half the two-sided value when z is in the predicted direction.
- **Reporting the p-value without the effect size.** A small p-value with a tiny difference may have little practical meaning. Report $p_1 - p_2$ alongside it.

## Limitations

The test relies on a normal approximation to the binomial distribution. When samples are small or the proportions are near 0 or 1, that approximation breaks down and the p-value can be misleading. Exact tests such as Fisher's exact test are safer in those cases.

The test also assumes independent observations within and between groups. Clustered data, repeated measures, or matched pairs violate this assumption and inflate the false positive rate. The test says nothing about causation either. A significant result means the proportions differ, not that one group's treatment caused the difference. For a broader comparison of when to use this test versus its alternatives, see [T-Test vs Z-Test: Which One to Use (With Examples)](/blog/research-skills/t-test-vs-z-test).

## Frequently Asked Questions

### What is the difference between a one-proportion and a two-proportion z-test?

A one-proportion z-test compares a single sample proportion to a fixed value. A two-proportion z-test compares two sample proportions to each other. The two-proportion version uses a pooled estimate and a standard error built from both samples.

### When should I use this test instead of a chi-square test?

For a 2x2 table, the two-proportion z-test and the chi-square test of independence give the same p-value, since $z^2$ equals the chi-square statistic. Use the z-test when you want a directional result or a confidence interval for the difference. Use chi-square for tables with more than two categories. The article on the [chi-square test formula](/blog/data-analysis/chi-square-test-formula-examples) covers the multi-category case.

### How large do my samples need to be?

A common rule is at least 5 successes and 5 failures in each group. Some texts prefer 10. Larger samples give a better normal approximation and more power to detect small differences. If your counts are below the threshold, use an exact test.

### Can the z statistic be negative?

Yes. A negative z means the first group's proportion is lower than the second group's. The sign tells you the direction of the difference. The p-value depends on the absolute value of z for a two-sided test.

### What does a p-value of 0.1380 mean in this example?

It means that if the two population proportions were equal, you would see a difference this large or larger about 13.8 percent of the time by chance alone. Since 0.1380 exceeds 0.05, you fail to reject the null hypothesis at that level. The result is not statistically significant at the 5 percent threshold.

## References

This article draws on the standard references listed under Further Reading.

## Further Reading

- [NIST/SEMATECH e-Handbook of Statistical Methods](https://www.itl.nist.gov/div898/handbook/index.htm)
- [Wasserstein RL, Lazar NA (2016). The ASA Statement on p -Values: Context, Process, and Purpose. The American Statistician](https://doi.org/10.1080/00031305.2016.1154108)
- [Krzywinski M, Altman N (2013). Significance, P values and t-tests. Nature Methods](https://doi.org/10.1038/nmeth.2698)
- [OpenStax. Introductory Statistics 2e](https://openstax.org/details/books/introductory-statistics-2e)
- [Krzywinski M, Altman N (2013). Importance of being uncertain. Nature Methods](https://doi.org/10.1038/nmeth.2613)
- [Greenland S, Senn SJ, Rothman KJ et al. (2016). Statistical tests, P values, confidence intervals, and power: a guide to misinterpretations. European Journal of Epidemiology](https://doi.org/10.1007/s10654-016-0149-3)

## Related Articles

- [Two Sample t-Test: Formula, Calculation and Example](/blog/data-analysis/two-sample-t-test-formula-example)
- [Z-Scores and Percentiles: How They Relate and How to Convert](/blog/data-analysis/z-scores-and-percentiles)
- [What Is a Chi-Square Test? Formula and Examples](/blog/data-analysis/chi-square-test-formula-examples)
- [Likelihood Ratio Test: Definition, Formula and Examples](/blog/data-analysis/likelihood-ratio-test)
- [What Is a Z-Score? Definition, Formula and Examples](/blog/data-analysis/what-is-a-z-score)
- [T-Test vs Z-Test: Which One to Use (With Examples)](/blog/research-skills/t-test-vs-z-test)
- [Test Statistic Formula: How to Calculate and Use It](/blog/guides/test-statistic-formula-how-to-calculate-and-use-it)
- [Understanding the Z-Table: How to Use It for Probability and Percentiles](/blog/guides/understanding-the-z-table-how-to-use-it-for-probability-and-percentiles)