← Blog

A/B test sample size calculator: stop guessing

An A/B test sample size calculator takes three inputs, your baseline conversion rate, the minimum lift you care about detecting, and your statistical power, and returns one number: how many users you need per variant before you look at the result.

Most teams skip the calculation. They launch a test, watch the dashboard for a week, and call it significant the moment a line crosses a threshold, without ever deciding up front how many users that threshold needs. That is how a team ships a change on a false positive, or runs a test for a month that never had the traffic to answer the question in the first place.

This guide pairs with A/B testing for developers, which covers assignment, guardrails, and concluding. This one is about the number you decide before any of that runs.

Key Takeaways

  • An A/B test sample size calculator needs three inputs: baseline rate, minimum detectable effect (MDE), and statistical power, and returns the number of users needed per variant.
  • Detecting a 10% relative lift on a 5% baseline conversion rate takes about 31,196 users per variant, at the standard 95% significance, 80% power convention.
  • The “rule of 16” (n ≈ 16 × p(1 − p) / δ²) gets within a few percent of the exact two-proportion z-test, fast enough to sanity-check a result in your head.
  • Halving the minimum detectable effect roughly quadruples the required sample size, because the formula divides by the squared difference.
  • Write the computed number into the experiment’s brief before launch, so the test has a stopping rule decided before anyone has seen data.

What an A/B test sample size calculator computes

Three numbers go in, one number comes out.

  • Baseline rate. The conversion rate your control already gets, from existing data, not a guess. A checkout flow converting at 5% needs a different sample than one converting at 30%.
  • Minimum detectable effect (MDE). The smallest lift worth shipping. A 10% relative lift is a common floor; smaller than that and the test needs far more traffic to detect it reliably.
  • Significance level and power. The convention is alpha = 0.05 (a 95% two-sided confidence level) and power = 0.80 (an 80% chance of detecting the effect if it is real). Evan Miller’s sample size calculator uses the same defaults, and most A/B testing tools follow suit.

Feed those three into the formula and the output is n, the number of users each variant needs before you check the result. Deciding that number ahead of time is what stops a glance at the dashboard from being mistaken for an answer.

The formula behind the sample size number

The exact version is the two-proportion z-test, the same test NIST’s engineering statistics handbook uses for comparing two proportions:

n = (z(α/2) + z(β))² · (p1(1 − p1) + p2(1 − p2)) / (p1 − p2)²

p1 is the baseline rate, p2 is the baseline rate plus the MDE, and z(α/2) and z(β) come from the normal distribution for your chosen significance and power (1.96 and 0.84 at the 95% / 80% convention). In code:

function sampleSizePerVariant(
  baselineRate: number,
  relativeLift: number,
  alpha = 0.05,
  power = 0.8
): number {
  const p1 = baselineRate;
  const p2 = baselineRate * (1 + relativeLift);
  const delta = p2 - p1;
  const zAlpha = 1.96; // two-sided, alpha = 0.05
  const zBeta = 0.84;  // power = 0.8
  const pooled = p1 * (1 - p1) + p2 * (1 - p2);
  return Math.ceil(((zAlpha + zBeta) ** 2 * pooled) / delta ** 2);
}

Run it with your own numbers. The math has no dependency on any tool: it is the same whether you read the result off a web calculator, a spreadsheet, or your own code.

A worked example: 5% baseline, 10% lift

A checkout page converts 5% of visitors today, and the hypothesis is that a benefit-led CTA lifts that by 10% relative, to 5.5%.

sampleSizePerVariant(0.05, 0.10) returns 31196.

That is 31,196 users per variant, 62,392 total, before the test has enough power to tell a real 10% lift from noise at the standard convention. At 5,000 checkout-page visitors a week split evenly across two variants, that test runs for about six weeks. If the number surprises you, it should: most teams guess at a one- or two-week test and run it at a fraction of the power they assume.

The rule of 16 (and where it breaks)

There is a faster estimate for when you just need an order of magnitude: n ≈ 16 × p(1 − p) / δ², where p is the baseline rate and δ is the absolute difference you want to detect. Evan Miller calls this the “rule of 16”, and it holds for the same 95% / 80% convention.

For the checkout example, 16 × 0.05 × 0.95 / 0.005² gives 30,400, within 3% of the exact 31,196 the z-test formula returns. Close enough to sanity-check a calculator’s output in your head, not close enough to replace it for a number you are about to commit six weeks of traffic to.

The rule of 16 also makes the cost of a smaller MDE obvious. Halving the lift you want to detect, from 10% relative to 5% relative on the same 5% baseline, halves δ and divides the denominator by 4: the sample jumps from about 30,400 to about 121,600 per variant. Precision is expensive, and it gets expensive fast.

Minimum detectable effect is the dial that matters

Baseline rate is what it is. You cannot change your own conversion rate to make the math easier. Significance and power are conventions you rarely touch. The one input you actually choose is the minimum detectable effect, and it is the one that decides whether your test finishes in a week or a quarter.

Pick an MDE smaller than the smallest lift that would be worth shipping, and you are measuring noise finely at a traffic cost nobody budgeted for. Pick one larger, and real wins smaller than your floor slip past undetected. Set the MDE to the smallest lift that would change what you ship next, then size the test to that number, not to how patient the team feels this week.

Write the number into the brief before you start

A sample size calculator only protects a test if the number gets written down before launch. Checking it against the result after someone already wants to stop defeats the purpose.

In a dif experiment file, that number belongs in the brief, next to the hypothesis. See the .md format for the full frontmatter reference:

---
id: checkout-cta-copy
status: active
owner: sam@acme.com
surface: checkout
hypothesis: >
  A benefit-led CTA ("Get it today") lifts completed checkouts
  by 10% relative over the control ("Buy now").
variants:
  - id: control
    weight: 50
  - id: get_it_today
    weight: 50
metrics:
  primary: completed_checkout
---

## Brief

Baseline: 5% checkout conversion. MDE: 10% relative lift.
Sample size: 31,196 per variant (95% significance, 80% power).
Do not conclude before both variants reach that number.

That last line is the stopping rule, decided before anyone has a result to react to. How not to run an A/B test, and the practice exp-platform.com documents, both say the same thing: deciding when to stop before you see data is what keeps a significant-looking result from being a coin flip you got excited about. The brief sits in the same file as the hypothesis and the variants, reviewed in the same pull request, part of the experimentation model instead of a number someone types into Slack once the line crosses it.

FAQ

What is a good sample size for an A/B test? It depends on your baseline rate and the smallest lift worth detecting; there is no fixed number. A 5% baseline test looking for a 10% relative lift needs about 31,000 users per variant at standard significance and power. A higher baseline or a bigger MDE needs far fewer.

How do I calculate sample size for an A/B test? Use the two-proportion z-test: n = (z(α/2) + z(β))² · (p1(1 − p1) + p2(1 − p2)) / (p1 − p2)², where p1 is your baseline rate and p2 is the baseline plus your minimum detectable effect. The rule of 16 (16 × p(1 − p) / δ²) gives a fast approximation.

What happens if my sample size is too small? The test is underpowered: it has a low chance of detecting a real effect even if one exists, and checking the result before reaching the planned size inflates the odds of a false positive. Either way, you cannot trust what the dashboard shows you.

Does a bigger sample size always mean a better test? No. Past the size needed for your MDE, you are detecting lifts too small to matter for the decision at hand. Set the MDE to the smallest lift worth shipping, then size to that, instead of running forever for more precision than the decision needs.

Can I use a sample size calculator for more than two variants? The same formula applies pairwise, each treatment compared to control, but testing more variants at once raises the chance that one looks significant by chance. Correct for that (a Bonferroni correction is the simplest) or hold each comparison to a stricter significance level.

Conclusion

A sample size calculator does not make an A/B test trustworthy by itself. It forces three decisions, baseline rate, minimum detectable effect, and power, that most teams currently make by instinct, if they make them at all.

The formula is a two-proportion z-test: n = (z(α/2) + z(β))² · (p1(1 − p1) + p2(1 − p2)) / (p1 − p2)². The rule of 16 gets you within a few percent for a quick check. Either way, the number belongs in the test’s brief before the first user is bucketed. Write it down after the line already looks good and it stops being a plan; it’s just a justification.

Run the function above with your own baseline and MDE, or use Evan Miller’s calculator if you want it without the code. Then write the result into the experiment file next to the hypothesis. To review that file in a pull request and conclude it with a recorded decision instead of a Slack thread, install the CLI:

npm install -g @dif.sh/cli
dif init

The first experiment guide walks through sizing and running one end to end.