Confidence Interval and Sample Size Calculator

Free confidence interval calculator for a mean or a proportion, with sample size for a target margin of error and a Central Limit Theorem simulator.
In progress

A confidence interval gives a range of plausible values for a population figure, such as a mean or a proportion, from a single sample. Its width depends on the spread of the data, the sample size and the confidence level. The same arithmetic run backwards tells you how large a sample you need for a given margin of error.

The tool opens on event-survey-data.csv, a sample survey of 200 event respondents. The Mean tab gives a t interval for Satisfaction, Spending or Waiting_Time_Mins. The Proportion tab gives Wald and Wilson intervals for the share who attended. Sample size works out n for a target margin of error. The CLT simulator draws repeated samples from the file and shows the sampling distribution of the mean take shape.

How it works

Mean: x̄ ± tn−1 × s / √nProportion, Wald: p̂ ± z √(p̂(1 − p̂) / n)Proportion, Wilson: (p̂ + z²/2n ± z √(p̂(1 − p̂)/n + z²/4n²)) / (1 + z²/n)Sample size, mean: n = (z σ / E)². Proportion: n = z² p(1 − p) / E², both rounded up

A worked example from the sample survey file: Satisfaction has n = 200, mean 3.814 and standard deviation 0.740. With t = 1.972 on 199 degrees of freedom, the 95% interval runs from 3.71 to 3.92. To estimate a proportion within 5 points at 95% confidence with no prior guess, n = 1.96² × 0.25 / 0.05² = 385.

The Wilson interval stays inside 0 to 1 and holds its coverage better than the Wald interval when the proportion is near 0 or 1 or the sample is small. The simulator treats the 200 rows as the population and draws samples with replacement, so the spread of the sample means can be checked against σ / √n. The tool’s t quantiles agree with R’s qt() to 6 decimal places. The margin of error post works through a proportion interval step by step.

Frequently Asked Questions

What does a 95% confidence interval mean?

If you took many samples and built a 95% interval from each, about 95% of those intervals would contain the true population value. Any single interval either contains it or misses it. The simulator shows this coverage directly.

When should I use t and when z?

Use t for a mean when the population standard deviation is estimated from the sample, which is almost always. The t distribution has heavier tails than the normal, and it approaches the normal as the sample grows. Proportion intervals use z.

What is the Wilson interval?

The Wilson score interval is a confidence interval for a proportion that stays inside 0 to 1 and keeps closer to its stated coverage than the Wald interval for small samples or proportions near 0 or 1. It matches R's prop.test with the continuity correction turned off.

How large a sample do I need?

For a proportion with no prior guess, 385 respondents give a margin of error of 5 points at 95% confidence. Halving the margin roughly quadruples the sample. For a mean, the answer depends on the standard deviation, which a pilot study can estimate.

What does the Central Limit Theorem say?

For a large enough sample, the sample mean is close to normally distributed around the population mean with standard error σ / √n, whatever the shape of the population. Skewed variables such as spending need a larger n before the shape settles.