Analytics
A/B Testing, Part 1: What It Is, How It Works and When to Use It
Part 1 of 3: What is an A/B test? Why random splits beat before-and-after? p-values and confidence intervals.
In this part
- What is an A/B test ?
- Why comparing before vs after" gives misleading results
- How to run a test: step by step, from hypothesis to decision
- How to determine a real test win from luck: p-values and confidence intervals in plain words
- When is an A/B testing right tool? How it differs from A/B/n and multivariate tests?
About the fictional company:
- Neelgiri Home is a made-up company, and it's our running example for this 3 part series on A/B testing.
- The company sells home decor (cushions, lamps and bedsheets) online, and its teams are debating a change to the product page.
It's design team is sure that bigger product photos and a "Delivered by Thursday" line near the top of the product page will get more people to add things to their cart.
On the contrary, the merchandising team thinks the bigger photos will push the price and the "Add to cart" button below the fold i.e. far down the screen, and sales will drop.
Both teams have opinions and slides, and the most senior person in the room has to pick a side. The question is how will she settle the debate ?
The answer is A/B test, it settles the debate with data instead. .
What is an A/B test?
An A/B test show 2 versions of something to 2 groups of people, at the same time, and measures which version does better.
- Version A, called as Control: The page as it is today.
- Version B, called the Variant: The page with the change i.e. bigger photos and the delivery date.
The trick in doing an A/B test is how people get sorted into the groups. Each visitor is assigned at random, like a coin flip. Heads and the 1st visitor see A; Tails and the 2nd visitor see B. A website visitor doesn't get to choose, and neither does the marketing team who is doing the test.
Because visitors land in a group at random, each group ends up with the same mix of people as the site as a whole. Let's say 70% of Neelgiri's product-page visitors shop on a phone and 30% on a laptop. Then roughly 70% of Group A and 70% of Group B are phone shoppers too. The same goes for new versus loyal customers, and for shoppers in Pune versus Guwahati, and even for things nobody tracks, like who's in a hurry. The groups are never identical to the last person, but the gaps are tiny and shrink as more visitors arrive. So the only systematic difference between them is the page they saw. If Group B adds more to cart, it's either the new page or plain luck, and the rest of the analysis is about ruling out luck.
Figure 1: How Neelgiri Home's product-page A/B test works. A random split, two versions, one comparison.
Drug trials have worked this way for decades: patients are randomly given the new drug or a placebo, and the trial compares how the two groups recover. An A/B test applies the same idea to a web page, an app screen, an email or a price.
📌 Key idea: Random assignment is what lets you say the change caused the difference.
Before vs after: Why not just launch it and compare before vs after?
It is tempting to ship a new page on the 15th and compare the fortnight after with the fortnight before.
The trouble is that everything else changes too. Let's say the page launched in the same week as a salary-week sale. Shoppers had money and discounts, and would have added more to cart whatever the page looked like.
Figure 2: Before-and-after credits the sale to the page (+25%). An A/B test run in the same weeks shows the page's real effect (+10%).
On the left, before-and-after shows a 25% jump and hands all of it to the new page. On the right, both A/B groups went through the same sale, so it cancels out, and the gap between them (about 10%) is what the page did.
Be it either festivals, ad campaigns, a competitor's outage or the monsoon: both A/B groups goes through all of them together.
A/B execution process, step by step
- Building Hypothesis. "If we show bigger photos and a delivery date, more visitors will add to cart, because shoppers can judge the product and know when it arrives." A good hypothesis names the change, the expected effect and the reason.
- Choose one Primary Metric. Neelgiri Home picks the add-to-cart rate defined as the share of product-page visitors who add the item to their cart. Part 3 covers how to choose this.
- Decide what gets Randomised. It is usually the user that is randomised. Each shopper is assigned once, and the testing tool remembers their group with a browser cookie or their account ID, so they see the same version every time they return. That gives the shopper a consistent experience, and it lets the test measure how they behave with the new change across all their visits.
- Sample Size and Test Duration. Part 2 covers this. For Neelgiri Home, it's 14 days.
- Test and Launch. Build the test and check whether it works on every device, then launch with a 50/50 split.
- Don't stop early. Don't stop early because the numbers look exciting. Part 3 explains why.
- Analyse and decide. Analyse the results and decide whether to ship it, drop it, or learn from it and test again.
Analyse Test Results: Is the gap real, or just luck?
Let's say after 14 days, each group had 28,000 visitors:
| Group | Visitors | Added to cart | Add-to-cart rate |
|---|---|---|---|
| A: Current page | 28,000 | 1,680 | 6.00% |
| B: New page | 28,000 | 1,848 | 6.60% |
The new page is 0.6 percentage points ahead, which is a 10% relative lift (0.6 ÷ 6.0).
⚠️ Pitfall: "Up 0.6%" and "up 10%" describe the same result. Going from 6.0% to 6.6% is +0.6 percentage points, or +10% relative.
Day-by-day movement of the primary metrics:
Figure 3: Daily add-to-cart rates for both groups. Single days are noisy; the dashed 14-day totals are what count.
Each dot is one day's add-to-cart rate, and the dashed lines are the 14-day totals. Group B was ahead on 11 of the 14 days, but on days 1, 2 and 9 the old page won. If we would have looked only at day 9 and we would have scrapped the new page.
So the question is: Is the 14-day gap real, or was it a lucky fortnight?
The precise question is: If the new page did nothing, how often would luck alone produce a gap this big?
We can answer the above question by brute force. Figure 4 shows 10,000 pretend tests where both groups saw the same page, so any gap is luck.
Figure 4: In 10,000 tests with no real difference, a gap of 0.6 points or more turned up just 34 times.
The grey bars are the gaps luck produces. Most fall within ±0.4 points. Only 34 out of 10,000 (the red slivers at the edges) reached 0.6 points in either direction. That share, about 0.3%, is the p-value. The exact calculation gives p = 0.0035.
The idea is to set a cut-off before the test, called the significance level, and 5% (0.05) is the common choice. If the p-value is below it, the result is statistically significant: too unlikely to be luck, so we treat it as real. Neelgiri Home's A/B test had a p-value of 0.0035 i.e. p < 0.05 which means the result is statistically significant.
The other number to report is the confidence interval, a range of plausible values for the true effect. Here, the 95% confidence interval for the lift is +3.3% to +16.7%. The new page almost certainly helps; how much it helps is less certain.
⚠️ Pitfall: A p-value of 0.0035 does not mean "99.65% chance the new page is better." It means a gap this big would be rare if the page did nothing. It's a statement about luck, not about the probability of your hypothesis.
A/A tests: Testing the test
Before trusting the testing tool there is a suggestion to run an A/A test: split visitors randomly but show both groups the same page. Apart from the odd false alarm (about 5% of the time, at a 5% significance level), it should find nothing. If A/A tests keep "finding" winners, the split, the tracking or the maths is broken.
When to use an A/B test?
A/B testing fits best when:
- The change is digital and we can control who sees it (a page, a button, an email, an app screen).
- We get enough traffic to reach the sample size in a few weeks.
- The outcome shows up quickly (a click, a cart, a sign-up), not months later.
- We can switch the change off if it flops.
A/B test examples:
- PaisaPal, a savings app, tests two versions of its sign-up screen. One says "Start saving in 2 minutes," the other "No paperwork. No branch visits." The primary metric is completed sign-ups.
- Swasth Labs, a diagnostics chain, tests sending its appointment reminder 24 hours before the visit versus 3 hours before. The primary metric is the no-show rate.
Similar concepts to A/B testing, the table below shows how they differ:
| Method | What it compares | Good for | Watch out for |
|---|---|---|---|
| A/B test | One control vs one variant | A single clear change | One idea per test |
| A/B/n test | Control vs several variants (B, C, D...) | Comparing three or four headlines | Traffic is split more ways, so it needs more visitors, and more comparisons mean more chances of a false win |
| Multivariate test | Every combination of several changes (photo size × button colour × headline) | Seeing how changes interact | The number of combinations grows fast; needs very high traffic |
| Before vs After | The same page before and after a launch | Rough monitoring when you can't randomise | Mixes the change with seasonality, sales and everything else |
Part 3 covers the cases where A/B tests don't work, like TV ads or very low traffic, and what to use instead.
Key Takeaways
- An A/B test randomly splits people between the current version (A) and a changed one (B), at the same time, so the change is the only systematic difference.
- Before-and-after comparisons mix the change with everything else that happened. Neelgiri Home's would have shown +25% when the page added about +10%.
- Use A/B tests for digital, reversible changes with enough traffic and outcomes you can measure within weeks.
➡️ Up next: Part 2: Sample Size, MDE and How Long to Run a Test works out where Neelgiri Home's 28,000 visitors and 14 days came from. It covers baseline rates, the minimum detectable effect, false wins and missed wins, power, and why tests run in whole weeks.
Quick Quiz: Test Yourself
🧠 Test yourself: 4 questions (click to open)
1. Why does an A/B test assign visitors to groups at random?
2. Neelgiri Home's add-to-cart rate went from 6.0% to 6.6%. Which description is correct?
3. What does a p-value of 0.0035 tell you?
4. A new page launches in the same week as a salary-week sale, and add-to-cart jumps 25% versus the week before. What's the problem?
In case of any queries or feedback, feel free to drop a comment or reach out using the Contact section.