How to Calculate Sample Size for A/B Testing (2026 Guide)
Sample size decides whether your A/B test can find a real effect. Here is the formula, a worked example, the four levers that move it, and why halving your MDE quadruples the traffic you need.
Published:
Sample size is the input that quietly decides whether your A/B test can succeed at all. Run too few users and even a genuine improvement stays buried in the noise, so you call a real winner “no effect” and move on. Calculate it up front and you know before you start whether the test is worth running. This guide shows you exactly how the number is built.
Sample size is the amount of traffic per variation you need to reliably detect an effect of a given size. It is not a fixed number you look up - it is the output of a short calculation driven by four inputs. Get the inputs right and the arithmetic is straightforward.
The four inputs that drive the number
Every sample size calculation, in every tool, comes down to these four levers.
- Baseline conversion rate. Your current rate for the metric you are testing, for example 5 percent of visitors buy. This sets the amount of natural variation in your data.
- Minimum detectable effect (MDE). The smallest improvement you want the test to be able to catch, expressed as an absolute jump (5 percent to 5.5 percent) or a relative lift (a 10 percent improvement). This is the lever teams set wrong most often - see our minimum detectable effect explained guide.
- Significance level (alpha). Your tolerance for a false positive, almost always 5 percent, which corresponds to 95 percent confidence.
- Statistical power. Your chance of detecting a real effect if one exists, conventionally 80 percent. Higher power means a bigger sample.
Change any one of these four and the required sample size moves. Nail them down before you touch a formula.
The formula, in plain terms
For a test comparing two conversion rates, the standard per-variation sample size is:
n = (z_alpha + z_beta)^2 * [ p1(1 - p1) + p2(1 - p2) ] / (p2 - p1)^2
Here p1 is the baseline rate, p2 is the baseline plus your MDE, and the z values come from your significance and power settings. For a two-sided test at 5 percent significance and 80 percent power, z_alpha is 1.96 and z_beta is 0.84, so (z_alpha + z_beta)^2 is about 7.84. This is the classic two-proportion formula and it is what calculators run under the hood.
The shape that matters is the bottom of the fraction - the effect size is squared, so the sample size grows with the inverse square of the effect you want to detect.
A worked example
Say your checkout converts at 5 percent and you want to detect a 10 percent relative lift - moving the rate to 5.5 percent. So p1 is 0.05, p2 is 0.055, and the absolute difference is 0.005.
n = 7.84 * [ 0.05(0.95) + 0.055(0.945) ] / (0.005)^2
= 7.84 * (0.0475 + 0.051975) / 0.000025
= 7.84 * 0.099475 / 0.000025
~= 31,200 per variation
You need roughly 31,000 users in each arm, about 62,000 total, before this test can reliably tell a 10 percent lift apart from luck. If your checkout sees 5,000 visitors a week, that is a 12-week test - which is a useful thing to know before you commit, not after.
Why the MDE dominates everything
Now watch what happens when you loosen the MDE from a 10 percent relative lift to a 20 percent one (p2 becomes 0.06):
n = 7.84 * [ 0.0475 + 0.06(0.94) ] / (0.01)^2
= 7.84 * 0.1039 / 0.0001
~= 8,150 per variation
| MDE (relative) | Absolute diff | Sample per variation |
|---|---|---|
| 20 percent lift | 0.010 | ~8,150 |
| 10 percent lift | 0.005 | ~31,200 |
| 5 percent lift | 0.0025 | ~124,000 |
Halving the effect you want to detect roughly quadruples the traffic you need. That inverse-square relationship is the single most important intuition in experiment design. It is why low-traffic teams should test bold changes with large expected effects, not button-color tweaks, and why demanding to detect tiny lifts commits you to tests that run for months.
Common mistakes that break the math
- Guessing the MDE from hope. Teams pick a tiny MDE because “even a 1 percent lift is worth it,” then are shocked the test needs half a million users. Set the MDE to the smallest lift that is genuinely worth shipping, not the smallest you can imagine.
- Using the wrong baseline. A sitewide conversion average is useless when you are testing one funnel step. Measure the baseline for the exact page and metric under test.
- Ignoring the number of variants. A/B/n tests split traffic across more arms and test more comparisons, so each arm needs its full sample and you should tighten significance to offset multiple comparisons.
- Stopping early when it looks significant. This is peeking, and it silently inflates false positives. Commit to the sample, or use sequential testing. Our statistical significance guide covers why.
Where the tools help
Most experimentation platforms bundle a power calculator so you do not do this by hand, and the better ones fold variance reduction into the estimate.
Statsig ships sequential testing and CUPED variance reduction. CUPED uses pre-experiment data to shrink the noise, which effectively lowers the sample size you need to reach the same power - a real edge when traffic is scarce. GrowthBook carries the deepest open-source engine, including CUPED, sequential testing and sample ratio mismatch checks that confirm your split actually landed at the ratio your sample size assumed. Optimizely built its reputation on a stats engine designed to stay valid under continuous monitoring, so you are less exposed to the peeking trap.
For choosing between them, see the best experimentation platforms roundup and Statsig vs GrowthBook.
The bottom line
Calculate sample size before you run the test, from your real baseline, an honest MDE, 5 percent significance and 80 percent power. The formula is one line, the intuition is inverse-square, and the payoff is knowing in advance whether an experiment can answer your question or is doomed to run forever. Size it first, commit to the number, and let a stats engine handle the rest.
Frequently Asked Questions
How do I calculate sample size for an A/B test?
You need four inputs - your baseline conversion rate, the minimum effect you want to detect, your significance level (usually 5 percent), and your statistical power (usually 80 percent). Plug them into the two-proportion sample size formula, or use a calculator. For a 5 percent baseline and a 10 percent relative lift you want to detect, you need roughly 31,000 visitors per variation at 80 percent power and 5 percent significance.
Why does a smaller effect need a bigger sample?
Because sample size scales with the inverse square of the effect size. The signal you are hunting for is the difference between variants, and the noise is the natural variation between users. To pull a smaller signal out of the same noise you need far more data. Halving the effect you want to detect roughly quadruples the sample size and runtime.
What baseline conversion rate should I use?
Use your actual current rate for the metric and page you are testing, measured over a representative recent window that covers full business cycles. Do not use a sitewide average if you are testing one specific funnel step - the baseline for that step is what drives the math. A wrong baseline throws the whole calculation off.
Can I stop an A/B test once it hits significance instead of the planned sample?
Not with a standard fixed-horizon test. Stopping the moment a result looks significant is peeking, and it inflates your false-positive rate well above the 5 percent you planned for. Either commit to the calculated sample size before you start, or use a tool with sequential testing that is statistically designed for continuous monitoring.
Explore More
Tool Reviews
Related Articles
- How to Design an A/B Test in 2026 - A Complete Framework
- How to Do A/B Testing in 2026 - A Practical Guide That Won't Lie to You
- How to Run an A/B Test in 2026 - A Step-by-Step Practical Guide
- Bayesian vs Frequentist A/B Testing - Which Stats Engine to Trust (2026)
- Confidence Intervals in A/B Testing - How to Read Them Right (2026)
Free Newsletter
Get the Feature Flags Newsletter
Platform benchmarks, real pricing data and progressive delivery practice. No spam.
Related Articles
Feature Flags in Python, Done Right - A 2026 Tutorial for Flask and Django
A hands-on guide to implementing feature flags in Python, from a hand-rolled dict toggle to production SDKs in Flask and Django. Real illustrative code and honest trade-offs.
July 28, 2026
how-toHow to Choose Metrics for A/B Testing - Primary, Secondary and the OEC (2026)
Most failed A/B tests fail at metric selection, not analysis. This guide shows how to pick one primary metric, structure secondary and guardrail metrics, avoid vanity metrics, and build an Overall Evaluation Criterion you can trust.
July 28, 2026
how-toHow to Design an A/B Test in 2026 - A Complete Framework
A trustworthy A/B test is won at the design stage, before a single user is bucketed. This framework walks the full design workflow - hypothesis, primary metric, guardrails, MDE, sample size, duration and analysis plan.
July 28, 2026
Statsig Review
GrowthBook Review
Optimizely Review