2 Sample Z Test Calculator
A two sample z test divides the gap between two group means by its standard error. For the worked example below, 82 against 79 with samples of 40 and 45 and standard deviations of 6 and 5 gives z = 2.487 and a two tailed p value of 0.0129, so the null hypothesis of equal means is rejected at the 0.05 level.
| Gap between the means | |
| Standard error of the gap | |
| z statistic | |
| p value for the test you picked | |
| p value, two tailed | |
| Critical value at your level | |
| Decision | |
| Pooled variance version, for comparison | |
| 95% confidence interval for the gap | |
The test assumes independent groups and treats the two standard deviations as known or well estimated, which is fair for large samples of 30 or more per group. With small samples and estimated spreads, a two sample t test is the better tool. All calculations happen in your browser, and no data is uploaded.
Enter two means, standard deviations and sample sizes to get the z statistic, the p value and a clear reject or keep call.
Key takeaways
- The z statistic is the gap between the two means divided by sqrt(s1²/n1 + s2²/n2), the standard error of that gap
- Use z when both population standard deviations are known, or when both samples are large, a common rule of thumb is 30 or more per group
- In the worked example, 82 against 79 with samples of 40 and 45 gives z = 2.487 and a two tailed p value of 0.0129, a reject call at the 0.05 level
- A one tailed p value is exactly half of the two tailed p value for the same z statistic
- Use a two sample t test instead when the samples are small and the standard deviations come from the data rather than from prior knowledge
- The critical values 1.645, 1.960 and 2.576 come from the standard normal table in the NIST/SEMATECH e-Handbook of Statistical Methods
On this page
- What a two sample z test answers
- The formula, and the two variance choices
- When z is valid and when you need t
- Worked example: two teaching methods
- One tailed against two tailed: a delivery example
- The pooled version on the same data
- Critical values and the decision rule
- Limits, mistakes, and what this test cannot do
What a two sample z test answers
A two sample z test asks whether two group averages differ by more than random noise allows. It takes a mean, a standard deviation and a sample size from each group, measures the gap between the two means, and weighs that gap against how much it would wobble if the study were repeated. The result is one number, the z statistic, and a p value that states how often chance alone would open a gap this wide if the two populations do share the same mean.
The test weighs evidence against one specific claim, the null hypothesis that both populations have the same mean. A small p value says the observed gap would be rare under that claim, so you reject it. A large p value says the gap fits comfortably inside everyday sampling noise, so you keep it. Neither outcome proves a cause, and neither says the difference is large. It only says how surprised you should be.
| Input | Role | Example value |
|---|---|---|
| Mean of group 1 | The average outcome in the first group | 82 |
| Standard deviation of group 1 | How spread out group 1 is | 6 |
| Sample size of group 1 | How many observations group 1 has | 40 |
| Mean, sd and n of group 2 | The same three numbers for the second group | 79, 5, 45 |
| Tails | Two tailed for any difference, one tailed for a difference in a stated direction | Two tailed |
| Significance level | The p value below which you reject, set before looking at the data | 0.05 |
The formula, and the two variance choices
The calculator uses the unpooled form of the test statistic:
z = (x̄1 − x̄2) / sqrt(s1²/n1 + s2²/n2)
x̄1 and x̄2 are the two sample means, s1 and s2 the two standard deviations, n1 and n2 the two sample sizes. Each group contributes its own squared spread over its own size, the two ratios are added, and the square root turns the sum into the standard error of the difference between the means. The z statistic is the observed gap counted in standard errors.
A pooled variant replaces the two separate variances with one combined variance:
s_p² = ((n1−1)s1² + (n2−1)s2²) / (n1+n2−2), then z = (x̄1 − x̄2) / sqrt(s_p² (1/n1 + 1/n2))
The pooled version assumes both populations share the same variance, and it buys a small gain in precision when that assumption holds. Use it when the two standard deviations are close, for example within about 20 percent of each other, and both samples are of similar size. When the spreads differ, the unpooled form above is the safer choice, which is why the calculator leads with it. Section 6 runs both versions on the same data so you can see how little they disagree when the assumption is reasonable.
When z is valid and when you need t
The z test treats the standard deviations as known numbers rather than estimates. That is the right model when a production process has a documented long run standard deviation, or when theory fixes the spread. It is also the accepted approximation when both samples are large, because a sample standard deviation from 30 or more observations is stable enough that the normal distribution describes the test statistic well. Penn State's STAT 500 course notes present exactly this split: known population standard deviations or large samples point to z, small samples with estimated spreads point to t.
The t test exists because an estimated standard deviation adds uncertainty, and with few observations that uncertainty is real. With n below 30 in a group, and the standard deviation estimated from that same small sample, the t distribution is the honest tool. The two distributions converge as the sample sizes grow, so the decision between them matters less once n passes a few dozen per group.
The test also assumes the two samples are independent, meaning no unit appears in both groups, and that each population is roughly normal, or the sample large enough for averages to sit near normal. Standard deviations that are wildly unequal with small samples also break the test, and no choice of z or t repairs that on its own.
Worked example: two teaching methods
Say two groups of students take the same final exam. Method A averaged 82 with a standard deviation of 6 across 40 students. Method B averaged 79 with a standard deviation of 5 across 45 students. The question is whether a 3 point gap is noise or signal. Set a two tailed test at the 0.05 level and compute step by step.
| Step | Computation | Result |
|---|---|---|
| 1. Gap between means | 82 − 79 | 3 |
| 2. Group 1 variance term | 6² / 40 = 36 / 40 | 0.900 |
| 3. Group 2 variance term | 5² / 45 = 25 / 45 | 0.556 |
| 4. Sum, then square root | sqrt(0.900 + 0.5556) = sqrt(1.4556) | 1.2065 |
| 5. z statistic | 3 / 1.2065 | 2.487 |
| 6. Two tailed p value | 2 × (1 − Φ(2.487)) | 0.0129 |
Step 6 uses the standard normal cumulative distribution, the function tabulated in the NIST handbook shown in section 7. The p value of 0.0129 sits below 0.05, so the test rejects the null hypothesis of equal means. A 95 percent confidence interval lands on the same call: 3 ± 1.960 × 1.2065 runs from 0.64 to 5.36, and the interval misses zero. The gap is between roughly two and three standard errors wide depending on the variance choice, which is why the p value is small without being extreme.
One tailed against two tailed: a delivery example
A courier wants to know whether a new routing rule raised average delivery time, not just changed it, so a one tailed test fits. The old route logged 150 deliveries with a mean of 32.4 minutes and a standard deviation of 8.1. The new route logged 175 deliveries with a mean of 30.9 and a standard deviation of 7.6. The gap is 32.4 − 30.9 = 1.5 minutes, and the standard error is sqrt(8.1²/150 + 7.6²/175) = sqrt(0.437 + 0.330) = sqrt(0.767) = 0.876. The z statistic is 1.5 / 0.876 = 1.712.
| Test | p value | Call at 0.05 |
|---|---|---|
| One tailed, new route faster | 0.0434 | Reject the null |
| Two tailed, any difference | 0.0869 | Keep the null |
The two rows answer different questions, which is why they disagree. The one tailed p value is exactly half the two tailed value, because it puts the whole 0.05 budget in one tail. Pick the tail before seeing the data. Choosing one tail after a first look, because it happens to be significant, is the classic way to manufacture a result that will not replicate.
The pooled version on the same data
Return to the teaching example and pool. The combined variance is s_p² = (39 × 36 + 44 × 25) / (40 + 45 − 2) = (1,404 + 1,100) / 83 = 2,504 / 83 = 30.169. The standard error becomes sqrt(30.169 × (1/40 + 1/45)) = sqrt(30.169 × 0.0472) = sqrt(1.425) = 1.194, and the pooled z statistic is 3 / 1.194 = 2.513, with a two tailed p value of 0.0120.
| Variance choice | Standard error | z | Two tailed p |
|---|---|---|---|
| Unpooled | 1.207 | 2.487 | 0.0129 |
| Pooled | 1.194 | 2.513 | 0.0120 |
The two calls agree here because the sample standard deviations, 6 and 5, are close and both samples are healthy sized. The pooled version borrows strength from the assumption of a common variance, so it lands slightly smaller standard error, slightly larger z, slightly smaller p. With standard deviations of 3 and 12 on small samples the gap between the two versions would widen, and the unpooled form would be the one to trust.
Critical values and the decision rule
An older but still common way to run the test skips p values. You compare the z statistic against a fixed critical value that marks the edge of the rejection region. The values below come from the standard normal table in the NIST/SEMATECH e-Handbook of Statistical Methods (NISTIR 7787, 2012), whose cumulative distribution table is the same function the calculator uses for p values.
| Significance level | Two tailed critical value | One tailed critical value |
|---|---|---|
| 0.10 | 1.645 | 1.282 |
| 0.05 | 1.960 | 1.645 |
| 0.01 | 2.576 | 2.326 |
Reject the null hypothesis when the z statistic passes the critical value in the relevant direction: outside ±1.960 for a two tailed test at 0.05, above 1.645 for a one tailed test at 0.05, and so on. The teaching example's z of 2.487 clears 1.960, matching the p value call of 0.0129 below 0.05. The delivery example's z of 1.712 clears 1.645 in one tail but not 1.960 in two, which reproduces the table in section 5. Critical values and p values are two readings of the same curve, so they never disagree when applied to the same test.
Limits, mistakes, and what this test cannot do
Small samples with estimated spreads. If a group has fewer than about 30 observations and you estimated its standard deviation from those observations, a two sample t test is the honest choice. The z form will report a smaller p value than the data support.
Dependent samples. If the same people appear in both groups, before and after measurements for instance, the groups are not independent and the two sample test answers the wrong question. Use a paired test on the differences.
Percentages and conversion rates. Proportions need their own z test, built on counts rather than means and standard deviations. Entering a rate of 0.42 as a mean with a made up spread will not reproduce the correct result.
Extreme spread imbalance. One group with a standard deviation several times the other, combined with small samples, can distort both versions of the test. Larger samples soften this, or use a test built for unequal variances.
Significance is not size. A z of 2.487 on samples of 40 and 45 rejects the null, but the estimated gap is still just 3 points with a confidence interval of 0.64 to 5.36. Report the interval next to the decision so readers can judge whether the difference matters in practice, not only whether it clears a threshold.
Frequently asked questions
When do I use a z test instead of a t test?
Use z when both population standard deviations are known, or when both samples are large enough that the sample estimates act like known values, with 30 or more per group as the common rule of thumb. With small samples and estimated spreads, use a two sample t test.
What does the p value mean in plain words?
It is the chance of seeing a gap between the two means at least this wide if the two populations share the same mean. In the worked example, p = 0.0129 means a gap like 82 against 79 would show up in about 13 of every 1,000 such experiments by pure chance.
What is the formula the calculator uses?
z = (x̄1 − x̄2) / sqrt(s1²/n1 + s2²/n2). It is the gap between the two means divided by the standard error of that gap, where the standard error combines each group's squared spread over its own sample size.
How do I choose between one tailed and two tailed?
Two tailed if you care about a difference in either direction. One tailed only if the direction was fixed before the data were collected. The one tailed p value is half the two tailed value: the delivery example gives 0.0434 one tailed against 0.0869 two tailed for the same z of 1.712.
What does a z of 1.96 mean?
It is the boundary of the rejection region for a two tailed test at the 0.05 level. A z statistic beyond +1.960 or below -1.960 rejects the null hypothesis of equal means. The value comes from the standard normal table, where 95 percent of the area sits between -1.960 and 1.960.
How big do the samples need to be?
The z approximation is comfortable with 30 or more observations in each group. With smaller groups, a two sample t test is more honest unless you truly know the population standard deviations. Very small differences between large samples can still turn significant, so pair the p value with the size of the gap.
What are the critical values at the 0.01 level?
For a two tailed test at the 0.01 level the critical value is 2.576, and for a one tailed test it is 2.326. Both come from the standard normal table in the NIST/SEMATECH e-Handbook of Statistical Methods (NISTIR 7787, 2012).
What if the two standard deviations are far apart?
Then the unpooled formula, the one this calculator uses, is the right default, because it keeps each group's spread separate. The pooled formula assumes a common variance and can mislead when the spreads differ, especially with small and unequal group sizes.
Can I use this test on percentages or conversion rates?
No. Comparing two proportions calls for a separate z test built on the counts of successes and trials. Entering a conversion rate as a mean with an invented standard deviation will not produce a valid p value.
Why does the calculator show both pooled and unpooled results?
So you can see the range. On the teaching example the unpooled z is 2.487 and the pooled z is 2.513, close enough that the decision does not change. When the two versions disagree, the unpooled one is the safer call unless you have solid grounds for a common variance.
Can the same subjects appear in both groups?
Not for this test. A two sample z test assumes independent groups. If each subject is measured twice, use a paired test on the within subject differences instead, since pairing changes the standard error completely.
Does a z statistic of 0 mean the groups are identical?
It means the two sample means happen to be equal, so the p value is 1.000 and there is no evidence of a difference. It does not prove the populations match, because two identical sample means can still come from different populations.
What null hypothesis does the test use?
That both populations have the same mean, written H0: mean1 = mean2. Rejecting it says the data are hard to explain under equal means. Failing to reject says the data are consistent with equal means, not that equality has been proven.
Is a significant result always a big difference?
No. Big samples make small gaps significant. The worked example rejects with a gap of 3 points, but the 95 percent interval for the true gap runs from 0.64 to 5.36, and only you can judge whether a difference in that range matters for the decision at hand.
Spotted a wrong number or a broken result?
More Math tools
Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.