Calculate minimum sample size for a checkout button A/B test
Statistics & ExperimentsModel answerLast updated
Given a baseline conversion rate and a target minimum detectable effect, compute the required per-variant sample size from first principles.
Scenario
You are a data scientist at an e-commerce company. The product team wants to test a redesigned checkout button (variant B) against the current one (variant A). Before running the experiment, your engineering lead asks you to justify how many users each variant needs.
Known facts:
- Current (baseline) checkout conversion rate: 5%
- Minimum detectable effect (MDE): you want to detect an absolute lift of 1 percentage point (i.e., variant B converts at 6% or worse is considered "no meaningful improvement")
- Significance level: α = 0.05 (two-tailed)
- Desired statistical power: 80% (β = 0.20)
What is expected
- State the formula for minimum per-variant sample size and explain where each term comes from.
- Plug in the numbers and compute (or closely estimate) the required sample size per variant.
- Interpret the result and flag at least two practical considerations the team should keep in mind when planning the test.
You may use the standard normal approximation. Show your reasoning step by step.
Hints
Hint 1
The formula relies on z-scores for α and β. For a two-tailed test at α=0.05, z_{α/2} ≈ 1.96; for 80% power, z_β ≈ 0.84. Write these down first before substituting anything.
Hint 2
The variance of a proportion p is p(1−p). You need to account for the variance under *both* the null (p_A) and the alternative (p_B) hypotheses—don't just use one of them.
Hint 3
After you get a raw number, sanity-check it: does a larger MDE require more or fewer users? Does a lower baseline variance (p closer to 0 or 1) require more or fewer users? Use these checks to verify your answer makes intuitive sense.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Step 1 — State the formula
For a two-proportion z-test (two-tailed), the minimum sample size per variant is:
n = (z_{α/2} + z_β)² × [p_A(1 − p_A) + p_B(1 − p_B)] / (p_B − p_A)²
Where each term comes from:
(z_{α/2} + z_β)²— combines the critical value for the false-positive rate (α) and the critical value for the false-negative rate (β). A higher bar for either error inflates this multiplier.p_A(1 − p_A) + p_B(1 − p_B)— sum of the variances of the two Bernoulli proportions. Because we are comparing two independent samples, their variances add.(p_B − p_A)²— the square of the effect size (MDE). Larger effects are easier to detect, so the denominator grows and n shrinks.
Step 2 — Identify all inputs
| Symbol | Value | Reason |
|---|---|---|
| p_A | 0.05 | baseline conversion rate |
| p_B | 0.06 | baseline + 1 pp MDE |
| z_{α/2} | 1.96 | two-tailed, α = 0.05 |
| z_β | 0.84 | power = 80% |
| MDE = p_B − p_A | 0.01 | absolute lift |
Step 3 — Compute each piece
Multiplier:
(1.96 + 0.84)² = (2.80)² = 7.84
Pooled variance term:
p_A(1 − p_A) = 0.05 × 0.95 = 0.0475
p_B(1 − p_B) = 0.06 × 0.94 = 0.0564
Sum = 0.0475 + 0.0564 = 0.1039
Denominator (squared MDE):
(0.01)² = 0.0001
Putting it together:
n = 7.84 × 0.1039 / 0.0001
= 7.84 × 1039
≈ 8,146 users per variant
Rounding up for conservatism: ~8,150 users per variant, or roughly 16,300 users total.
Step 4 — Interpret the result
At the site's current traffic volume, the team can divide this total by the daily eligible user count to determine runtime. For example, if 2,000 users reach checkout daily and 100% are enrolled, the test needs about 8 days. If only 50% are enrolled (one variant each), it needs roughly 16 days.
Step 5 — Practical considerations
1. Runtime vs. novelty effects Running a test too long risks external factors (seasonality, campaigns) confounding results. Running it too short risks underpowering. Aim for at least one full weekly cycle; avoid launching during atypical traffic spikes.
2. The MDE choice drives everything A 1 pp absolute lift on a 5% baseline is a 20% relative lift — ambitious. If the team is willing to accept detecting only a 0.5 pp lift, sample size quadruples (denominator shrinks by 4×). Align with stakeholders on what lift is business-meaningful before locking the MDE.
3. Multiple metrics / multiple testing If the team also monitors secondary metrics (average order value, bounce rate), the effective α inflates. Apply a Bonferroni correction or pre-register primary vs. guardrail metrics to avoid false discoveries.
4. One-sided vs. two-sided test If the team only cares about detecting an increase (never wants to ship a regression), a one-tailed test uses z_α ≈ 1.645 instead of 1.96, reducing the required n by ~15%. Justify this choice explicitly before the test starts.
Common mistakes to avoid
- Forgetting the two-sample structure: using only p_A's variance (as if comparing to a fixed constant) underestimates n.
- Confusing relative and absolute MDE: "detect a 20% lift" means p_B = 0.06, not 0.25.
- Peeking and stopping early: checking significance before the pre-determined n is reached inflates the false-positive rate well above 5%, even if each individual look uses α = 0.05.
- Ignoring the allocation split: the formula above assumes a 50/50 split. An unequal split (e.g., 10% treatment to reduce risk) requires a correction and substantially increases total n.