ThisCalculator

Everyday

Calculator 2 Sample Z Test? How to Run & Interpret

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

A two-sample z-test calculator determines whether the difference between two population means is statistically significant when the population standard deviations are known. You enter the sample means, sample sizes, and population standard deviations (or variances) for both groups, and the calculator returns the z-statistic and p-value. This article explains the formula, how to use the calculator, assumptions, and common pitfalls.

Formula

The two-sample z-test statistic is calculated as:

z = (x̄₁ − x̄₂) / √(σ₁²/n₁ + σ₂²/n₂)

  • x̄₁, x̄₂ = sample means of group 1 and group 2
  • σ₁, σ₂ = population standard deviations (known)
  • n₁, n₂ = sample sizes

The denominator is the standard error of the difference between the two means. The result, z, follows a standard normal distribution under the null hypothesis that the true means are equal.

The p-value (two-tailed) is the probability of observing a z-statistic as extreme as, or more extreme than, the calculated value, in either direction. For a one-tailed test, you would halve the two-tailed p-value.

Worked Example

Suppose you compare two manufacturing processes. Group 1 has a sample mean of 100, a known population standard deviation of 15, and a sample size of 30. Group 2 has a sample mean of 105, a known population standard deviation of 15, and a sample size of 30.

  1. Calculate the standard error: √(15²/30 + 15²/30) = √(225/30 + 225/30) = √(7.5 + 7.5) = √15 ≈ 3.873
  2. Compute the difference in means: 100 − 105 = −5
  3. Divide by the standard error: −5 / 3.873 ≈ −1.291
  4. Take the absolute value for the two-tailed p-value: |z| = 1.291
  5. Find the two-tailed p-value: 2 × (1 − Φ(1.291)) ≈ 2 × (1 − 0.9015) = 0.197

The calculator gives z ≈ −1.291 and p ≈ 0.197. Since p > 0.05, you would not reject the null hypothesis at the 5% significance level; the difference is not statistically significant.

When to Use a Two-Sample Z-Test

Use this test when you have two independent random samples and you know the population standard deviations (σ). This is rare in real research—usually σ is unknown and you would use a two-sample t-test instead. Typical applications include quality control with known machine variability, or large-scale studies where the population variance has been established from previous data.

Key conditions:

  • Independent samples (no pairing or matching)
  • Known population standard deviations (or large samples where sample SD is a good estimate, but strictly the z-test requires known σ)
  • Normally distributed populations, or large sample sizes (central limit theorem)
  • Random sampling

How to Interpret the Results

The z-statistic tells you how many standard errors the observed difference is from zero. A larger absolute z-value indicates stronger evidence against the null hypothesis.

The p-value is the probability of getting a difference at least as large as yours if the true means were equal. Common significance levels:

  • p < 0.05: statistically significant at the 5% level
  • p < 0.01: statistically significant at the 1% level
  • p ≥ 0.05: not statistically significant (fail to reject H₀)

You can also compare the z-statistic to critical values (e.g., ±1.96 for a two-tailed test at α = 0.05). If |z| > 1.96, reject the null hypothesis.

Common Mistakes and Misconceptions

  • Using sample standard deviations instead of population σ. The z-test assumes known σ; if you estimate σ from the sample, use a t-test. With large samples (n > 30), the t-test approaches the z-test, but it’s safer to use t when σ is unknown.
  • Mixing up one-tailed and two-tailed p-values. The calculator gives two-tailed by default. If your hypothesis is directional (e.g., mean1 > mean2), halve the p-value, but only if you decided that before seeing the data.
  • Ignoring the assumption of independence. If samples are paired (e.g., before/after), a paired test is needed.
  • Rounding too early. Keep at least 4 decimal places in intermediate steps to get accurate results.
  • Misinterpreting “not significant” as “no difference.” A non-significant result does not prove the means are equal; it just means the data are not strong enough to conclude a difference.

Z-Test vs. T-Test

The main difference is whether the population standard deviation is known. The z-test uses σ; the t-test uses the sample standard deviation s and accounts for extra uncertainty with the t-distribution. For small samples (n < 30) and unknown σ, the t-test is preferred. For large samples, both give similar results, but the t-test is more conservative when σ is unknown.

Another difference: the z-test is based on the normal distribution, while the t-test uses a family of distributions that depend on degrees of freedom. As sample size grows, the t-distribution approaches the normal.

Limitations of the Two-Sample Z-Test

The test is only valid if the population standard deviations are truly known. In most real-world scenarios, you don’t know σ, so the z-test is rarely the correct choice. Even with large samples, using sample SDs in a z-test can lead to slightly inflated type I error rates, though the effect diminishes with sample size.

Also, the test is sensitive to outliers and non-normality, especially with small samples. If the data are heavily skewed, consider a nonparametric alternative like the Mann-Whitney U test.

Frequently Asked Questions

What is the difference between a z-test and a t-test?

A z-test requires known population standard deviations, while a t-test uses sample standard deviations. The t-test is more common because population σ is usually unknown. For large samples, the results are very similar.

Can I use a two-sample z-test if I don’t know the population standard deviation?

Strictly, no. The z-test formula assumes σ is known. If you only have sample standard deviations, use a two-sample t-test. With large samples (n > 30), some practitioners use z as an approximation, but it’s safer to use t.

What does the p-value mean in a two-sample z-test?

The p-value is the probability of observing a difference between sample means as large as (or larger than) yours, assuming the true population means are equal. A small p-value (e.g., < 0.05) suggests the difference is unlikely due to chance alone.

How do I choose between one-tailed and two-tailed tests?

Choose a two-tailed test if you are testing for any difference (either direction) without a prior expectation. Choose a one-tailed test only if you have a strong theoretical reason to expect a specific direction (e.g., mean1 > mean2) before collecting data. The calculator gives the two-tailed p-value; halve it for a one-tailed test.

What is the minimum sample size for a two-sample z-test?

There is no strict minimum, but the test relies on the normal approximation. For non-normal populations, a common rule of thumb is n ≥ 30 per group. If the population is normal, smaller samples are acceptable, but the z-test still requires known σ.

Can I use the two-sample z-test for proportions?

No. For comparing two proportions, you need a two-proportion z-test, which uses a different formula. This calculator is for means only.

Related

Formula used
in x1 | Sample 1 mean | - | 100 | 0
in s1 | Sample 1 std dev | - | 15 | 0
in n1 | Sample 1 size | - | 30 | 1
in x2 | Sample 2 mean | - | 105 | 0
in s2 | Sample 2 std dev | - | 15 | 0
in n2 | Sample 2 size | - | 30 | 1
out z | z-statistic | - | (x1 - x2) / sqrt((s1^2/n1) + (s2^2/n2)) | 4
out p | p-value (two-tailed) | - | 2 * (1 - normcdf(abs(z))) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.