Bell Statistics

Two-sample t-test calculator

Work out how many observations each group needs before you run, then get the t statistic, p-value and confidence interval once the data is in. Welch's version is the default, because equal variances are an assumption you rarely have grounds for.

Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

Calculator

Your numbers

The smallest difference worth detecting.

Pooled, from historical data.

n₂ ÷ n₁. 1 is an even split.

Test settings

Enter your numbers on the left and the result appears here.

When to use it

Use a two-sample t-test when you have one continuous measurement and two independent groups, and you want to know whether their averages differ by more than sampling noise would explain. Revenue per user in control against treatment, session length on two onboarding flows, delivery time from two warehouses — anything where each observation belongs to exactly one group and no observation is paired with another.

The independence requirement is the one that quietly fails in product work. If the same user appears in both groups, or the same user contributes several sessions, the observations are not independent and the test will report a p-value smaller than the evidence deserves. Repeated measurements on the same unit want the paired t-test or a model that accounts for the clustering; three or more groups want one-way ANOVA rather than a series of pairwise t-tests, which inflates the false-positive rate — see the problem of multiple comparisons.

If your outcome is a rate rather than a measurement — conversion, click-through, retention at day 7 — you want the A/B test sample size calculator instead. And if your question is "are these two groups the same?" rather than "do they differ?", a non-significant t-test does not answer it; an equivalence test does.

Assumptions

The t-test rests on three assumptions, and they are not equally fragile:

  • Independence, within and between groups. This is the assumption that matters. There is no correction to apply after the fact and no diagnostic plot that reveals it — it is a property of how you assigned units, not of the data you collected.
  • Approximate normality of the group means, not of the raw data. The Central Limit Theorem does most of the work here: with a few hundred observations per group, even visibly skewed data produces means that are near enough normal. Small samples of heavily skewed or long-tailed data are the real problem, and revenue per user is exactly that shape. See our note on what to do when data is not normally distributed, or use the Wilcoxon test if you would rather not assume it.
  • Equal variances — for Student's version only. Welch's version drops this assumption at a cost of a fraction of a degree of freedom, which is why it is the default here and the default in R. There is no good reason to run Student's t-test after a variance test; that two-step procedure has worse error rates than simply using Welch throughout.
  • Outliers are not an assumption, but they will dominate the result. A single extreme value can move both the mean and the standard deviation enough to flip a conclusion — see tackling outliers in A/B testing.

How the calculation works

The sample-size tab solves the exact non-central t power function, not the normal approximation. The approximation is off by a few percent at small n, which is precisely where the answer matters, and the exact version costs nothing to compute. Power is the probability that the test rejects when the true difference is the one you specified — so the number you get back is conditional on that difference being real, which is why the effect size you enter should be the smallest difference worth detecting rather than the one you hope to see.

Test statistic (Welch)
t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)

Student's version replaces the denominator with the pooled standard error, sₚ√(1/n₁ + 1/n₂).

Degrees of freedom (Welch–Satterthwaite)
df = (s₁²/n₁ + s₂²/n₂)² / [ (s₁²/n₁)²/(n₁−1) + (s₂²/n₂)²/(n₂−1) ]

Non-integer, and lower than n₁ + n₂ − 2 whenever the variances differ. That is the price of dropping the equal-variance assumption, and it is small.

Effect size (Cohen's d)
d = (μ₁ − μ₂) / σ

The difference expressed in standard deviations. Sample size depends on the ratio, not on the two quantities separately: a 2-point difference with σ = 5 needs exactly the same n as a 0.4-point difference with σ = 1.

Power
1 − β = P( |T′| > t₁₋α/₂,df ), ncp = d·√(n₁n₂/(n₁+n₂))

T′ is non-central t with the stated non-centrality parameter. Achieved power is reported at the rounded-up n, so it is always at or slightly above the target you asked for.

Confidence interval
(x̄₁ − x̄₂) ± t₁₋α/₂,df · SE

The interval and the p-value always agree: the interval excludes zero exactly when p < α.

Worked example

You are testing a new checkout flow and the outcome is revenue per session. Historical sessions average $10.00 with a standard deviation of $5.00, and the smallest improvement that would justify shipping the change is $2.00. You want 80% power at the conventional 5% two-sided significance level, with traffic split evenly.

Significance level (α)
0.05, two-sided
Power (1 − β)
0.80
Mean, group 1
10.00
Mean, group 2
12.00
Standard deviation
5.00
Allocation ratio
1:1

100 sessions per group, 200 in total. Cohen's d is 0.40 and achieved power at n = 100 is 80.4%.

Two hundred sessions is the cost of being able to detect a $2.00 lift four times out of five. It is not the number that guarantees you will see one: if the true lift is $1.00 rather than $2.00, this design has about 29% power, and the most likely outcome is an inconclusive test that gets read as "no effect". Halving the detectable difference roughly quadruples the sample size, which is the single most useful thing to know before negotiating a test's scope.

Interpreting the output

The p-value is the probability of seeing a difference at least this large if the two groups genuinely had the same mean. It is not the probability that the null hypothesis is true, and it is not the probability that the result will replicate. A p of 0.03 says the data would be somewhat surprising under no effect; it says nothing about how large the effect is.

Read the confidence interval first. It carries everything the p-value carries — it excludes zero exactly when p < α — and it also tells you the range of differences the data is consistent with. An interval of [$0.10, $4.20] is technically significant and practically useless: it cannot distinguish a trivial lift from a transformative one. An interval of [−$0.20, $0.30] is not significant, but it is genuinely informative, because it rules out anything worth acting on. Reporting the interval rather than the p-value alone is the main recommendation in our guide to reporting A/B test results properly.

A non-significant result is not evidence of no difference. If you need to demonstrate that two options are interchangeable — that a cheaper vendor performs no worse, that a refactor changed nothing — the t-test is the wrong instrument. Use an equivalence test to show the difference falls inside a margin you nominate in advance, or a non-inferiority test if only one direction concerns you.

Finally, the power you calculated before the test tells you nothing new after it. Post-hoc power computed from the observed effect is a deterministic function of the p-value and adds no information; if the test was inconclusive, the useful question is what the confidence interval rules out, not what the power "was".

Frequently asked questions

Should I use Welch's t-test or Student's t-test?
Welch, essentially always. It does not assume the two groups have equal variances, and when they happen to be equal it costs almost nothing — a fraction of a degree of freedom. The common practice of running a variance test first and choosing between the two based on the result produces worse error rates than simply using Welch throughout, because the choice is itself made from the data. R has defaulted to Welch for this reason for decades.
Can I use a one-sided test to reduce the sample size?
You can, and it reduces the required n by roughly 20% at conventional settings — but only if you would genuinely take no action on a result in the opposite direction, and only if you decide that before seeing any data. Switching to one-sided after a two-sided test disappoints is a way of manufacturing significance, not of finding it. We wrote about the trade-off in detail in one-sided vs two-sided tests.
I don't know the standard deviation yet. What do I put in?
Take it from historical data on the same metric and the same population — the previous month of the same funnel step is usually the best available estimate. If you have nothing, run a short pilot and use its standard deviation, or express the difference you care about in standard deviations directly (Cohen's d) and set the standard deviation to 1. What you should not do is guess low: the required sample size scales with the square of the standard deviation, so a 30% underestimate leaves you with about half the power you planned for.
Does an uneven split between groups cost me anything?
Yes, and more than most people expect. A 1:1 split is optimal when the two groups have similar variances. A 2:1 split needs about 12% more total observations for the same power, and a 4:1 split about 56% more. Uneven allocation is sometimes worth it — limiting exposure to a risky change, or reusing a large existing control group — but it should be a deliberate trade, not a default.
My data is skewed. Is the t-test still valid?
Usually, provided the groups are reasonably large. The test assumes the sampling distribution of the mean is approximately normal, not that the data is, and with a few hundred observations per group the Central Limit Theorem delivers that even for visibly skewed distributions. The genuine problem cases are small samples of very long-tailed data — revenue per user with a handful of whales is the classic example — where a few observations dominate both the mean and the variance. There, either use the Wilcoxon test, analyse a transformed or winsorised outcome, or bootstrap the interval.
My result is significant but the difference looks tiny. What now?
That is what a large sample buys you: the ability to detect differences too small to matter. Statistical significance answers "is it distinguishable from zero?", not "is it worth shipping?". Compare the confidence interval against the smallest difference that would change your decision — the one you should have nominated before running the test. If the whole interval sits below it, you have a real but immaterial effect, and the correct conclusion is to ship or not on other grounds.

Related calculators

  • Paired t-test

    Before-and-after or matched pairs — size the study on the difference SD, then test it.

  • One-way ANOVA

    Three or more independent groups on one continuous outcome — size it, then run the F test.

  • Wilcoxon test

    Rank-sum (Mann-Whitney) and signed-rank tests, with the exact distribution for small samples.

  • Equivalence: two means

    Show two averages are close enough to be interchangeable — set the margin, size the study, run both one-sided tests.

Terms on this page

  • Average treatment effect

    What a randomised test estimates — the population average, which can describe nobody in particular.

  • Average treatment effect on the treated

    The effect on the people who actually got it — usually the honest question when uptake was voluntary.

  • Bootstrap

    Resample your own data ten thousand times and watch the answer wobble — uncertainty for statistics with no formula.

  • Causal inference

    Estimating what an action caused by reconstructing what would have happened without it.

  • Central limit theorem

    Why averages go bell-shaped even when the data do not — the result that makes ordinary tests work.

  • Counterfactual

    The outcome you did not get to see — and every method in causal inference is a way of estimating it.

  • CUPED

    Use pre-period data to strip out noise — the same test, 20-50% less traffic, no change to the estimate.

  • Degrees of freedom

    The count of what is still free to move — and the number that decides how demanding your significance threshold is.

  • Difference-in-differences

    Subtract the untreated group's change from the treated group's — and everything rests on parallel trends.

  • Effect size

    How big the difference is — the number a p-value throws away and a business case runs on.

  • Geo experiment

    Randomise regions instead of users — the way to test marketing that cannot be hidden from a person.

  • Local average treatment effect

    The effect on the people your assignment actually moved — not the population, and not the adopters.

Browse the full statistics glossary

Talk to the people who build these for a living

We design and run experiments where the sample size, the metric and the decision rule are agreed before anyone looks at the data. A/B Testing

References