Sample Size Calculator for Two Means
Calculate n for comparing two means.
Effect size must be a positive number
Enter effect size and standard deviation to calculate sample size
What Is Sample Size Calculation for Comparing Means?
Before running an experiment comparing two groups, you need to know how many subjects per group are required to detect a meaningful difference. Too few subjects and you'll miss real effects; too many wastes resources.
This calculator determines sample size based on:
- Expected effect size (how large a difference you anticipate)
- Significance level (α, typically 0.05)
- Desired power (1 - β, typically 0.80 or 0.90)
The Key Inputs
Effect Size (Cohen's d)
The standardized difference you want to detect:
| d | Interpretation | Example |
|---|---|---|
| 0.2 | Small | Subtle educational intervention |
| 0.5 | Medium | Typical psychological effect |
| 0.8 | Large | Clear treatment difference |
Smaller effects need larger samples.
Significance Level (α)
The probability of a false positive (Type I error):
- α = 0.05: 5% chance of detecting difference when none exists
- α = 0.01: More conservative, larger sample needed
Power (1 - β)
The probability of detecting a true effect:
- Power = 0.80: 80% chance of detecting a real difference
- Power = 0.90: More stringent, larger sample needed
The Formula
For a two-sample t-test with equal group sizes:
Where:
- = critical z-value for significance level
- = critical z-value for power
- = effect size
Example: d = 0.5, α = 0.05 (two-tailed), power = 0.80
z₀.₉₇₅ = 1.96, z₀.₈₀ = 0.84
n = 2 × [(1.96 + 0.84)² / 0.5²] = 2 × [7.84 / 0.25] = 63 per group
Practical Examples
Medical Trial
"Will a new drug lower cholesterol by at least 10 mg/dL?"
Expected difference: 10 mg/dL Pooled SD: 25 mg/dL d = 10/25 = 0.40
For α = 0.05, power = 0.80: n ≈ 100 per group
Educational Intervention
"Does the tutoring program improve test scores?"
Expected improvement: 5 points SD: 15 points d = 5/15 = 0.33
For α = 0.05, power = 0.80: n ≈ 144 per group
Manufacturing Comparison
"Is process B faster than process A?"
Expected difference: 2 minutes SD: 5 minutes d = 2/5 = 0.40
For α = 0.05, power = 0.80: n ≈ 100 per group
Sensitivity Analysis
Run calculations for multiple scenarios:
| Effect Size | Power 0.80 | Power 0.90 |
|---|---|---|
| 0.2 (small) | 393 | 526 |
| 0.5 (medium) | 64 | 86 |
| 0.8 (large) | 26 | 34 |
This table helps planning when effect size is uncertain.
One-Sided vs. Two-Sided Tests
Two-sided (more common): Tests for difference in either direction. Uses z₁₋α/₂ in formula.
One-sided: Tests for difference in one direction only. Uses z₁₋α, requiring fewer subjects.
Use one-sided only with strong prior justification.
Unequal Group Sizes
If groups must be unequal (e.g., 2:1 ratio):
The formula adjusts for the allocation ratio k = n₂/n₁.
For k = 2 (twice as many in group 2):
- Total sample increases slightly
- Useful when one condition is cheaper or easier
Common Mistakes
Underestimating Variability
If actual SD is higher than assumed, you'll be underpowered. Use conservative estimates or pilot data.
Optimistic Effect Sizes
Researchers often overestimate expected effects. Use realistic estimates based on prior research.
Ignoring Attrition
Plan for dropouts by inflating sample size:
If 20% dropout expected:
Forgetting to Multiply
The formula gives per-group sample size. Total sample = 2n for two equal groups.
Historical Context
Jerzy Neyman and Egon Pearson developed power analysis foundations in the 1930s.
Jacob Cohen (1969, 1988) made power analysis accessible to researchers with his books and effect size conventions.
Despite decades of advocacy, many studies remain underpowered. Meta-analyses repeatedly find that typical studies have power of only 20-50% for detecting realistic effects.
Post-Hoc Power: Don't Do It
Calculating power after seeing results is meaningless:
- High p-value → low post-hoc power (circular)
- It doesn't answer "Was my study adequately powered?"
Power analysis should be done before data collection.
Related Calculations
- Sample Size for Two Proportions — For binary outcomes
- Statistical Power Calculator — Given n, find power
- Cohen's d Calculator — Estimate effect size from data
- Minimum Detectable Effect Calculator — What effect can you detect?
- CI for Difference in Means — Analyze results
Summary
Sample size calculation for comparing means balances practical constraints against statistical needs. Given your expected effect size, significance level, and desired power, the formula determines how many subjects per group are required. Small effects need large samples; large effects need few. Plan conservatively—underestimate effect sizes, overestimate variability, and account for dropout. Adequate sample size is essential for meaningful research that can detect true effects when they exist.