You believe showing the delivery date on the product page will lift orders. A week after the change, conversion is up; but that week included payday and a running campaign. Can you credit the change? The answer to how to run an A/B test closes exactly this gap: you split visitors at random into two groups, show one the current page and the other the new page, and measure whether the difference is more than chance.
In this guide we use an e-commerce example to cover how to write the hypothesis, choose primary and guardrail metrics, calculate the sample size step by step, decide how long to run, avoid the peeking and multiple-comparison traps, check for sample ratio mismatch (SRM), read the result and work out the return on the test. All figures are representative; they are not an industry average or a measurement from a real customer.
What Is an A/B Test?
An A/B test is a controlled experiment in which you split visitors at random into groups at the same time to measure the effect of one change. Group A sees the current experience (the control), group B sees the changed experience (the variant), and the two groups differ only by that change. The day of the week, a campaign or the season affects both groups equally.
In a before-and-after comparison, everything that changes over time leaks into the effect; in an A/B test it does not. If you plan to test the checkout, read our checkout guide; if you plan to test search, read our site search guide. This article focuses on the experiment itself.
When Should You Run an A/B Test, and When Not?
Run one when you have enough traffic, one measurable goal and a change that is easy to roll back; otherwise pick another method.
| Method | What it does | When it fits | Weakness |
|---|---|---|---|
| A/B test | Compares two versions in random groups at the same time | Enough traffic and a clear metric | Needs a large sample and time |
| Before-and-after comparison | Compares the period before and after a change | Random assignment is impossible (e.g. a price list) | Campaigns, seasons and weekdays blur the result |
| Multivariate test | Changes several elements at once and measures combinations | Very high traffic | Every combination needs its own sample |
| Usability test | Watches a few people to learn why | Low traffic, or when you need the reason | Does not measure the effect as a number |
A practical rule: if the sample size you calculate exceeds eight weeks of your traffic, do not test that change. Try a bigger change or go back to usability testing. If you are validating a brand-new product idea, our MVP guide fits better.
How Do You Write a Good Hypothesis?
A good hypothesis ties an observation, a change, an expected effect and a measure together in one sentence. "If we make the page prettier, conversion rises" is not a hypothesis; it says neither what changes and why, nor how it will be measured.
The pattern is: "Because of [observation], if we show [audience] [change], [primary metric] will change by at least [difference]." Our example: "Support tickets show customers cannot find the delivery date on the product page. If we show an estimated delivery date next to the add-to-cart button, orders per product-page visitor will rise by a relative 10%."
A hypothesis should rest on an observation: support tickets, the drop-off point from customer journey analysis, or user interviews. Ideas without observations waste tests, because a change with a small effect is expensive to detect (see the sample size table below).
How Do You Choose Primary and Guardrail Metrics?
Choose one primary metric; it makes the decision. Next to it, put guardrail metrics that check nothing else gets worse while the primary metric rises.
| Metric type | Role | Example | Rule |
|---|---|---|---|
| Primary | Decides the winner | Orders per visitor | Exactly one; written before the test starts |
| Guardrail | Checks for harm | Average basket value, page load time, payment errors, support tickets | A "may worsen by at most" threshold is written in advance |
The metric must match the unit of analysis: if you assign by visitor, "orders per visitor" is the natural metric. Highly variable metrics such as revenue need a large sample; a rate-based measure is usually more practical. We explained how to define and threshold indicators in our KPI guide.
What Should the Randomization Unit Be?
The unit is the entity the decision is made for: in most e-commerce tests, the unique visitor. If you assign by session or page view, the same person sees different versions and the experience becomes inconsistent.
Assignment must be stable: a visitor should see the same version on every return. The way to do it is to hash the visitor ID together with the experiment name and map it to a fixed bucket; we explained the mechanics of gradual rollout in our feature flags guide. For signed-in users, an account ID reduces the chance of one person landing in different groups on two devices. Because you store an identifier for assignment, settle cookie and consent requirements with your legal counsel.
When customers compare prices with each other, visitor-level assignment can be unreliable; for price tests, see our price optimization guide.
How Do You Calculate the Sample Size for an A/B Test?
The number of visitors each arm needs depends on the baseline conversion rate, the smallest difference you want to detect, the significance level and the statistical power. The common formula for comparing two proportions is:
n = (zα/2 + zβ)² × [p₁(1 − p₁) + p₂(1 − p₂)] ÷ (p₂ − p₁)²
For α = 5% (two-sided), z = 1.96; for 80% power, z = 0.84; the square of the sum is (1.96 + 0.84)² = 7.84. In our representative example the baseline conversion is p₁ = 2.0% and the smallest difference we want to catch is a relative +10%; so p₂ = 2.2%.
- p₁(1 − p₁) = 0.02 × 0.98 = 0.0196
- p₂(1 − p₂) = 0.022 × 0.978 = 0.021516
- Sum = 0.041116
- Numerator = 7.84 × 0.041116 = 0.322349
- Denominator = (0.022 − 0.02)² = 0.000004
- n = 0.322349 ÷ 0.000004 ≈ 80,587, rounded up to 80,588 visitors per arm; 161,176 in total.
This smallest difference (the minimum detectable effect, MDE) means: if the true effect is this large, the test catches it with 80% probability. Halving the difference roughly quadruples the sample:
| Smallest difference (relative) | p₂ | Visitors per arm | Duration at 5,000/day per arm | Planned duration |
|---|---|---|---|---|
| +20% | 2.4% | 21,082 | 4.2 days | 14 days (floor) |
| +10% | 2.2% | 80,588 | 16.1 days | 21 days (3 weeks) |
| +5% | 2.1% | 314,847 | 63 days | 63 days (9 weeks) |
There is also a quick rule of thumb: n ≈ 16 × p(1 − p) ÷ (difference)²; in the example 16 × 0.0196 ÷ 0.000004 = 78,400, close enough for a first estimate.
How Long Should an A/B Test Run?
Duration is the required sample divided by daily traffic per arm, then rounded up to whole weeks. Days of the week behave differently, so stopping after half a week skews the result.
In the example, 10,000 visitors a day enter the test; with two arms that is 5,000 per arm. 80,588 ÷ 5,000 = 16.1 days, so we plan 21 days, three full weeks; by then each arm holds 105,000 visitors, above the required number. A two-week floor also lets the novelty effect fade so you can see it.
More arms split the traffic. With one control and three variants, each arm gets 2,500 visitors a day. With the multiple-comparison correction below, the required sample also rises: about 107,500 ÷ 2,500 = 43 days, which is seven weeks. Adding arms makes a test expensive.
Why Is Peeking a Problem?
Checking results every day and stopping the moment they look significant pushes the false-positive rate far above 5%. The threshold was computed for a single look.
A simple bound: if the looks were independent, the chance that at least one of five looks is significant by luck would be 1 − 0.95⁵ ≈ 22.6%. Because the looks are correlated, the real rate is lower, but still clearly above 5%. The fix is to write the duration in advance and not decide until it ends, or to choose sequential methods that account for repeated looks from the start. Watching is fine; stopping because of a technical problem (a broken page) is also legitimate.
What Are Multiple Comparisons and Segment Hunting?
The more comparisons you make, the more likely one looks "significant" by chance. Comparing three variants with one control gives a 1 − 0.95³ ≈ 14.3% chance of at least one false positive.
The simplest correction divides the threshold by the number of comparisons: 0.05 ÷ 3 ≈ 0.0167, which gives z ≈ 2.394. The sum in the formula becomes (2.394 + 0.84)² = 10.459, so the sample rises to 80,588 × 10.459 ÷ 7.84 ≈ 107,500; about 33% more per arm. Segment hunting is the same trap: if the result is not significant, slicing the test into ten segments finds a chance "winner" with probability 1 − 0.95¹⁰ ≈ 40.1%. Write the segments before the test starts; those you find afterwards become the hypotheses of a new test.
What Is Sample Ratio Mismatch (SRM) and How Do You Check It?
SRM is when the real group sizes deviate from the planned ratio by more than chance can explain; it signals an error in assignment or measurement.
Example: the plan is 50/50, and of 100,000 visitors 50,900 went to control and 49,100 to the variant. The expectation is 50,000. Chi-square = 900² ÷ 50,000 + 900² ÷ 50,000 = 16.2 + 16.2 = 32.4. With one degree of freedom, a common alarm threshold is 10.83 (p < 0.001); 32.4 is far above it: there is SRM and the result is not used until it is investigated. With 50,200 and 49,800 the chi-square would be 1.6; chance. Typical causes: a redirect error, bots, measurement code that fires late and filters applied after assignment. To validate the assignment pipeline itself, run an A/A test with two identical arms before the real test; if it comes out significant, the pipeline is faulty.
How Do You Read an A/B Test Result?
Read the result with two numbers: the size of the difference and its confidence interval. The p-value is the probability of seeing a difference this large or larger if there were truly no difference; it does not tell you the probability that the effect is real.
After three weeks, each arm holds 105,000 visitors. Control had 2,100 orders (2.00%), the variant 2,268 orders (2.16%). The difference is 0.16 points, a relative +8.0%. The pooled rate is 4,368 ÷ 210,000 = 0.0208; the standard error is about 0.000623; z = 0.0016 ÷ 0.000623 ≈ 2.57; the two-sided p ≈ 0.010. The 95% confidence interval is 0.0016 ± 1.96 × 0.000623 = +0.04 to +0.28 points; in relative terms roughly +1.9% to +14.1%.
| Measure | Value | How to read it |
|---|---|---|
| Observed difference | +0.16 points (+8.0%) | The best single estimate |
| p-value | ≈ 0.010 | Hard to explain by chance; not "certain" |
| 95% confidence interval | +0.04 … +0.28 points | The true effect may be small or large |
| Planned smallest difference | +0.20 points (+10%) | The interval covers it, but its lower end is far lower |
Decision: if the result is statistically significant and the guardrail metrics held, ship it; but write the expectation as "between +2% and +14%", not "+8%".
What If the Result Is Inconclusive?
If the interval includes zero, do not say "there is no effect"; say "this sample could not separate the effect". In the same example, if the variant had 2,205 orders (2.10%), the difference would be +0.10 points, z ≈ 1.62, p ≈ 0.106 and the interval −0.02 to +0.22 points (about −1.1% to +11.1% relative).
You then have three options: ship it if it is cheap, retest with a bigger change, or drop the idea. Continuing "just a bit longer" is peeking in disguise. For ordering your ideas, see our RICE prioritization guide.
How Do You Keep an Experiment Log and Roll Out the Winner?
Every experiment goes into a log: hypothesis, primary and guardrail metrics, smallest difference, sample size, planned duration, dates, SRM result, confidence interval and decision. That way the same idea is not retested, and losing tests still teach something.
Roll the winner out gradually behind a flag (5%, 25%, 100%); keeping a small share on control for a while shows whether the effect lasts. For variants that affect speed, load time is a guardrail metric: see our website speed guide. To confirm a variant works correctly before launch, see our software testing guide.
How Do You Calculate the Return on an A/B Test?
The return is the monthly contribution the test creates divided by the cost of building and analyzing it. In the representative example, 300,000 visitors a month at 2.0% give 6,000 orders; the contribution per order is ₺200.
- Observed +8%: 6,000 × 0.08 = 480 orders × ₺200 = ₺96,000 a month.
- Cost: design, development and analysis of 12 person-days × ₺9,000 = ₺108,000.
- Payback: 108,000 ÷ 96,000 ≈ 1.1 months.
- Lower end of the interval (+1.9%): 6,000 × 0.019 = 114 orders × ₺200 = ₺22,800 a month; 108,000 ÷ 22,800 ≈ 4.7 months.
Saying "1.1 months at the best estimate, 4.7 months at the lower end" is more honest than a single number. Not every test wins; judge the experiment budget by total learning, not only by the winners.
How to Run an A/B Test in Six Steps
- Hypothesis: observation, change and expected difference in one sentence.
- Metrics: one primary, a few guardrail metrics and their thresholds.
- Sample size: visitors per arm from the smallest difference and power; no test if traffic is short.
- Assignment: stable assignment, A/A validation, SRM check.
- Run: the pre-written duration, in whole weeks; no stopping except for technical problems.
- Decide and log: confidence interval, guardrail metrics, log entry, gradual rollout.
We recommend reading: How to Set Up Cookie Consent Management: Cookie Policy, Banner, Tag Loading and Measurement Impact Guide
We recommend reading: How to Build a Landing Page: One Goal, Message Match, Form and Measurement Guide
We recommend reading: How to Design User Onboarding and the First-Run Experience: Activation, Product Tours, Empty States and Measurement
Building A/B Testing Infrastructure with İnovabil
At İnovabil our focus is building company-specific software from scratch: e-commerce, web and custom software. Experiment infrastructure (stable assignment, measurement, release behind flags) is not needed in every project; for software with many visitors it is worth evaluating. Our process page records the analysis, design, development, test, release and maintenance steps; we suggest settling your measurement expectations during analysis.
We built CRM, purchasing and mobile for Avcılar İnşaat; a purchasing system for İZBAN; logistics and shipment planning with wholesale order management for Karyak; and warehouse management plus a complaint and support system for Sleepy. The figures in this guide are not measurements from these projects.
We recommend reading: Our custom software service
We recommend reading: Our software development process: step by step from analysis to release
Frequently Asked Questions
How do you run an A/B test?
Write the hypothesis and primary metric, calculate the sample size from the smallest difference, assign visitors to two groups at random and stably, check for SRM, run for the pre-set duration and read the result with a confidence interval.
How many visitors does an A/B test need?
For a 2.0% baseline and a relative +10% difference, at 5% significance and 80% power, about 80,588 visitors per arm. The number changes with the baseline and the difference; this figure is representative.
How long should an A/B test run?
Divide the required sample by daily traffic per arm and round up to whole weeks; two weeks at least. In the example it comes to 16.1 days, so we plan three weeks.
Can I stop the test as soon as it turns significant?
No; deciding before the pre-set duration ends raises the false-positive rate. Stopping because of a technical error is a separate matter.
If the p-value is below 0.05, has the variant definitely won?
No. The p-value measures the chance explanation; it does not tell you the size of the effect. Look at the confidence interval, the guardrail metrics and the business impact together.