Statistical Calculators › Means: One and Two Groups › Two-Sample z-Test Sample Size (Known Variance)
← All Calculators

Means: One and Two Groups

Two-Sample z-Test Sample Size (Known Variance)

Calculate the required sample size for comparing two independent population means when the population variances are known. Supports one-sided and two-sided tests, unequal known variances, and equal or unequal allocation between the two groups. Runs entirely in your browser.

Study Design

Specify the difference you want to detect, known population variances, significance level, power, and group allocation.
z = (μ₁ − μ₂) / √(σ₁²/N₁ + σ₂²/N₂)

Required Sample Size

The smallest integer sample size that reaches the requested power under the specified normal-theory z-test.
Enter the study parameters and click Calculate Sample Size.

Methodology

This calculator implements the two-sample z-test for two independent means when the population variances are known. The null hypothesis is H0: μ1 − μ2 = 0, with either a two-sided alternative or a one-sided alternative.

Test Statistic

When the population variances are known, the standard error of the difference between two independent sample means is

SE = √(σ₁²/N₁ + σ₂²/N₂)

Z = (μ̄₁ − μ̄₂ − δ₀) / SE

For the usual superiority calculation, the null difference δ0 is zero. The sample-size calculation uses the anticipated difference δ = |μ1 − μ2| as the effect to be detected.

Power Calculation

Under the anticipated alternative, the standardized effect is

η = |δ| / √(σ₁²/N₁ + σ₂²/N₂)

For a two-sided test with significance level α, the exact normal approximation used here is

Power = 1 − Φ(z1−α/2 − η) + Φ(−z1−α/2 − η)

For a one-sided test, the corresponding expression is

Power = 1 − Φ(z1−α − η)

where Φ is the standard normal cumulative distribution function. Rather than relying on a rounded closed-form approximation, the calculator searches over integer sample sizes and returns the first allocation whose calculated power is at least the requested target.

Group Allocation

With equal allocation, N1 = N2. With ratio allocation, the calculator uses N2 = R × N1 and searches over integer N1, rounding N2 upward to the next whole participant when necessary.

For equal allocation, the familiar approximate closed-form expression follows directly from the standardized effect:

N per group ≈ (σ₁² + σ₂²) (z1−α/2 + z1−β)² / δ²

The actual implementation performs the power calculation directly and searches for the smallest integer sample size, which also accounts for the small contribution of the opposite tail in a two-sided test.

Worked Validation Example

this method provides a validation example using a two-sided two-sample z-test with 90% target power, α = 0.05, equal allocation, a mean difference of 2, and known standard deviations of 4.1 and 5.3. Equivalently, the known variances entered here are σ₁² = 16.81 and σ₂² = 28.09.

Target power = 0.90
α = 0.05
δ = 2
σ₁ = 4.1   →   σ₁² = 16.81
σ₂ = 5.3   →   σ₂² = 28.09
Allocation = N₁ = N₂

Expected: N₁ = 118, N₂ = 118, Total N = 236
Actual power ≈ 0.90013

The JavaScript implementation below reproduces this validation result: 117 participants per group gives power below 0.90, whereas 118 per group gives power approximately 0.90013. Thus 118 per group is the smallest integer allocation satisfying the target.

Assumptions

References

the software, LLC. (2023). Two-Sample Z-Tests Allowing Unequal Variance. this method Sample Size Software, Chapter 428. the relevant methodological literature describes sample-size and power calculations for one- and two-sided two-sample z-tests with known unequal variances and provides the worked validation example used above.
this method procedure documentation

the software, LLC. (2023). Two-Sample Z-Tests Assuming Equal Variance. this method Sample Size Software, Chapter 426. This documentation gives the corresponding known-common-variance two-sample z-test and cites Julious (2010) and Chow, Shao, and Wang (2008) as references for the power and sample-size methodology.
this method equal-variance procedure documentation

Julious, S. A. (2010). Sample Sizes for Clinical Trials. Boca Raton: CRC Press/Taylor & Francis. Chapter 3 covers sample-size calculations for parallel-group superiority trials with normal data.

Julious, S. A., Tan, S. B., & Machin, D. (2010). Sample Size Calculations for Clinical Trials. In An Introduction to Statistics in Early Phase Trials, pp. 37–53. Wiley. DOI: 10.1002/9780470686164.ch3 .

Statsols /. Advanced User Manual, Section 7.2.5.1, “Two Means (GST1).” The documentation expresses the maximum information for an inequality two-sample z-test in terms of σ₁²/N₁ + σ₂²/N₂ and relates the information to the standardized mean difference.
Advanced User Manual