Tools
Sample size calculators by goal
Start by deciding whether your study needs to estimate a parameter within a margin of error, or set up a hypothesis test with a target power. These are different problems that rely on different assumptions.
To estimate a parameter (confidence interval)
Use these tools when the main output will be a confidence interval for a mean, a proportion or a difference. You need to set the confidence level, the margin of error and the expected variability.
Means
3Proportions
3Variance and association
2To design a hypothesis test
Use these tools when you want to detect a difference, an association or a minimum relevant effect. You need to set the significance level, the power and the effect size.
Means and group comparisons
5Proportions, A/B testing and 2×2 tables
5- One-proportion testH0: p = p0 with α, power and alternative
- Two independent proportionsPer group, with α, power and minimum difference
- Paired proportionsMcNemar: discordant pairs and power
- Odds ratio (case-control)Case-control: OR, exposure and case/control ratio
- Fisher's exact test2×2 tables with the Fleiss correction
Variances, correlation and association
4Goodness of fit and normality
3Theory
What is sample size and why does it matter?
Sample size is the number of observations you need to collect to answer a research question with a predefined level of precision and reliability. Working it out before starting the study is essential: a sample that is too small produces unreliable results (it fails to detect real effects and yields wide confidence intervals); an oversized sample wastes resources without any meaningful gain.
The exact formula varies with the goal, but in every case n grows when you demand more precision or more power, and shrinks when the expected effect is large or the variability is low. The underlying logic is always the same: keep the estimation or decision error under control at an acceptable cost.
Two main approaches
Estimation (precision)
You want to know the value of a parameter (mean, proportion) within a maximum margin of error. You fix the confidence level \(1-\alpha\) and the admissible error \(E\); the minimum sample keeps the expected margin of error within \(E\) as long as the assumptions about variability (the assumed \(\sigma\) or proportion) hold. If the real variability is larger, or the variability estimated from the data turns out larger, the resulting interval may be wider.
Calculators: one proportion, difference of two proportions, one mean, paired means, variance, odds ratio and finite population.
Hypothesis test (power)
You want to detect a difference, association or effect if it really exists. You fix the significance level \(\alpha\), the power \(1-\beta\) and the minimum relevant effect size. The sample ensures that, with that probability, the test will reject \(H_0\) when it is false.
Calculators: two proportions, two means, paired means/proportions, ANOVA, correlation, non-inferiority and odds ratio.
Key concepts
- Significance level (\(\alpha\)): the maximum probability of a Type I error (rejecting a true null hypothesis). The usual value is 0.05, which corresponds to a 95% confidence level.
- Power (\(1-\beta\)): the probability of detecting a real effect when it exists. The most common targets are 80% and 90%. Increasing power requires a larger sample.
- Type II error (\(\beta\)): the probability of failing to detect a real difference (false negative). It is complementary to power: \(\beta = 1 - (1-\beta)\).
- Effect size: the minimum relevant magnitude you want to detect (difference of means, difference of proportions, correlation…). The smaller the effect, the larger the sample must be.
- Margin of error (\(E\)): in estimation studies, the maximum tolerable deviation between the sample estimate and the population value.
- Variability: the expected spread of the variable (standard deviation \(\sigma\) for means, \(p(1-p)\) for proportions). More uncertain values force you to use conservative assumptions.
- Finite population: when the sample represents an appreciable fraction of the total (\(n/N > 5\%\)), a correction factor applies that reduces the required sample size.
Guide
Which calculator should I use?
Answer these questions to go straight to the right tool, without mixing up estimation and hypothesis-test goals.
-
What is your main variable?
- Percentage or rate → proportion calculators.
- Continuous value (weight, time, score) → mean calculators.
-
Do you want to estimate or to test, and how many groups do you have?
- You only need to estimate a parameter with a margin of error → one proportion, difference of two proportions, one mean or paired means.
- One group against a reference value → one-proportion test or one-mean test.
- Two independent groups to test a difference → two proportions or two means.
- Two measurements on the same subject (before/after, pairs) → paired means or paired proportions.
- Three or more groups (k groups) → ANOVA.
-
Is there a special design goal?
- Detecting a correlation between two continuous variables → Pearson correlation.
- Showing that a treatment is no worse than, or interchangeable with, another → non-inferiority / equivalence.
- Case-control study with odds ratio as the effect measure → odds ratio (case-control).
-
Is the total population known and relatively small?
- Yes → apply the finite population correction (proportion) or finite population correction (mean).
- No (or it's very large) → use the standard calculators.
Practical guide
Quick guide to planning a sample
Before computing \(n\), define precisely what you want to measure and with what guarantees. Changing the goal midway through the study invalidates the original calculation.
- Define the primary metric before collecting data. A study with multiple primary variables requires computing \(n\) for each one and taking the largest sample, or adjusting the significance level.
- Use conservative assumptions if you don't have pilot data. For proportions with no prior information, use \(p = 0.5\) (maximum variability). For means, look for estimates of \(\sigma\) in similar literature.
- Account for expected dropout. Once you have \(n\), divide it by \((1 - \text{dropout rate})\). For example, if you expect 15% dropout, recruit \(n / 0.85\) subjects.
- Always round up. Sample size is a whole number; never truncate it.
- Document your assumptions. Record the margin of error and confidence level (for estimation), or \(\alpha\), power, expected effect and variability (for a hypothesis test), so you can justify the design and recompute it if conditions change.
Practice
Worked examples
Example 1: satisfaction survey (one proportion)
You want to estimate the percentage of satisfied customers within a maximum margin of error of ±5% and a 95% confidence level. With no prior information you use \(p = 0.5\). The formula is:
\( n = \frac{z_{\alpha/2}^{2}\, p\,(1-p)}{E^{2}} = \frac{(1.96)^2 \cdot 0.5 \cdot 0.5}{(0.05)^2} \approx 385 \)
You need at least 385 valid responses. If the company only has 1,000 customers, apply the finite population correction and the sample shrinks to about 278.
Example 2: clinical trial (two independent means)
You want to detect a 5-point difference on a pain scale between treatment and control, with an estimated standard deviation of 10 points, 80% power and two-sided \(\alpha = 0.05\). The per-group formula is:
\( n = \frac{2\,\sigma^2\,(z_{\alpha/2}+z_{\beta})^2}{\delta^2} = \frac{2 \cdot 100 \cdot (1.96+0.84)^2}{25} \approx 63 \)
You need 63 subjects per group (126 in total). Use the two-means calculator to fine-tune these parameters.