Sample Size Calculator

Estimate how many samples (or simulation runs) you need to hit a target confidence interval, for continuous or binary outcomes. Based on the Determining Replications series.

Instructions & field descriptions
Data type
Continuous / Integer: use when you're estimating a mean or average of a numeric measurement (e.g., runtime, cost, a simulation output) — this uses a standard deviation estimate to size the sample. Binary / Categorical: use when you're estimating the fraction of a population falling into one category (e.g., proportion answering "yes," proportion with an event, pass/fail) — this uses a proportion estimate instead. Pick whichever matches the quantity you're actually trying to pin down with your confidence interval.
Test type
Two-sided (default): use whenever a deviation in either direction from the true value matters — e.g., "the true mean could be higher or lower than my estimate." This is the standard choice for most confidence intervals and splits your significance level across both tails. One-sided: use only when you care about deviation in a single direction — e.g., confirming a metric is "at least" or "at most" some value. One-sided tests put your entire significance level in one tail, so for the same confidence level they require a smaller Z (and smaller n) than a two-sided test. This choice only applies when Bonferroni correction is off — see below for what happens when it's on.
Standard deviation (σ)
Your best estimate of the population standard deviation, in the same units as your measurement. In order of preference: (1) an estimate from pilot data or a comparable prior study, (2) a conservative published estimate for a similar population, (3) as a rough rule of thumb, range ÷ 4 (since ~95% of data falls within 2 standard deviations of the mean). When uncertain, overestimate — it's the safer failure mode, since underestimating σ yields an interval wider than intended.
Confidence level
How confident you want to be that the true value falls within your interval. 95% is standard for most analyses; use 99% when errors are costly, or 90% for exploratory work. Higher confidence requires a larger sample.
Margin of error (continuous)
The half-width of your confidence interval, in the same units as your data — e.g., a margin of ±2 means your estimate could plausibly land up to 2 units from the truth in either direction. Set it relative to the scale of what you're measuring; smaller margins always require larger samples.
Population size (N)
Leave blank to assume an effectively unlimited population sampled with replacement (typical for simulation studies). If you're sampling without replacement from a known, bounded population (e.g., all patients at a clinic), enter it here — the finite population correction will reduce the required n once your sample becomes a non-trivial fraction of N.
Bonferroni correction
If you're testing multiple hypotheses or comparisons simultaneously, the chance of at least one false positive rises. Bonferroni corrects for this by dividing the significance level by the number of tests (m), which increases the Z-score used and therefore the required sample size. Number of hypotheses (m) is the total number of tests/comparisons in the family. Enabling Bonferroni replaces the Test Type choice above: every one of the m tests is assumed to be one-sided, matching the classic Bonferroni derivation used in the linked blog post, where each test's full significance budget (not half of it) is divided by m. The correction can be overly conservative when m is large or the tests are correlated.