Tools

Confidence Interval Calculator

Confidence intervals for a mean or proportion, with full working

%
Confidence interval
–

How to calculate a confidence interval

  1. Choose what you are estimating: a mean from summary statistics, a mean from raw data you paste in, or a proportion (such as the share of survey respondents who said yes).
  2. Enter the values: mean, standard deviation and sample size; or your data; or the number of successes and the sample size.
  3. Pick the confidence level. 95% is the usual choice.
  4. Read the interval, the margin of error and the full working: standard error, critical value and the formula used, ready for homework or a report.

The formulas

For a mean, the interval is x̄ ± t* × s/√n, where s/√n is the standard error and t* is the critical value of Student's t distribution with n − 1 degrees of freedom. For 95% and n = 25, t* = 2.064, so a sample with mean 50 and SD 10 gives 50 ± 2.064 × 2 = 50 ± 4.13, or 45.87 to 54.13. If the population standard deviation is genuinely known, z* is used instead (1.960 for 95%). The t value is computed exactly for any sample size, not looked up in a rounded table.

For a proportion, the simple Wald interval is p̂ ± z* × √(p̂(1 − p̂)/n). It is taught widely but behaves badly for small samples or proportions near 0% or 100%, so the default here is the Wilson score interval, which statisticians recommend and which never goes below 0 or above 1. For 45 successes out of 100 at 95%, Wilson gives 35.6% to 54.8%.

A 95% confidence interval means that if you repeated the sampling many times, about 95% of the intervals built this way would contain the true value. It does not mean there is a 95% chance that this particular interval contains it. Wider intervals come from smaller samples, more variable data or higher confidence levels; to halve the margin of error you need about four times the sample size.

When should I use t instead of z?

Use t whenever the standard deviation comes from your sample, which is almost always. z is only for a known population standard deviation, or as an approximation for very large samples.

What is the z value for a 95% confidence interval?

1.960. For 90% it is 1.645 and for 99% it is 2.576.

What is the margin of error?

Half the width of the interval: the critical value times the standard error. A poll result of 45% ± 3 points has a margin of error of 3 percentage points.

How large a sample do I need?

For a proportion with a ±3-point margin at 95%, about 1,068 people in the worst case (p = 50%). The sample size calculator works this out for other margins.