A confidence interval turns a single sample estimate into a range of plausible values for the population parameter. Instead of saying "the average is 50", you say "the average is 50 ± 4.1 at 95 % confidence" — the estimate, plus an honest statement of how precise it is.
This calculator covers the three intervals met in almost every introductory course and in day-to-day analysis:
- A mean, from the sample mean, standard deviation and size. Use Student's when the standard deviation was estimated from the sample (the usual case), or when the population is genuinely known.
- A proportion, from a number of successes out of . The calculator defaults to the Wilson score interval, which keeps close to its nominal coverage even with small samples or proportions near 0 or 1, and shows the classic Wald interval next to it for comparison.
- The difference between two means, from two independent samples, with Welch's unequal-variance method (default) or the pooled-variance method.
Pick a confidence level from 80 % to 99.9 %. You get the interval, its bounds, the margin of error, the standard error, the critical value $z^$ or $t^$, the degrees of freedom and a table of the same interval at other confidence levels.
How to use this calculator
- Choose what the interval is for: a mean, a proportion or two means.
- Select the confidence level — 95 % is the convention in most fields.
- Mean: enter , the standard deviation and ; say whether the standard deviation comes from the sample () or is a known population value ().
- Proportion: enter the number of successes and the sample size (for 81 "yes" out of 263, type 81 and 263). Keep Wilson unless a course asks for Wald.
- Two means: enter the mean, standard deviation and size of each sample; keep Welch unless you have a good reason to assume equal variances.
- Read the interval and margin of error; the steps show the standard error and the critical value used.
The formula
All three intervals have the form estimate ± critical value × standard error, with $z^* = \Phi^{-1}(1 - \alpha/2)$ and .
Mean (NIST e-Handbook §1.3.5.2):
Proportion, with . Wald and Wilson score (Wilson 1927; Agresti & Coull 1998):
Difference of two means (Welch):
The pooled version uses , standard error and degrees of freedom.
Worked example
Mean, σ unknown. A sample of has and . The standard error is , and with 24 degrees of freedom $t^* =$ 2.0639 at 95 %. The margin of error is 2.0639 = 4.1278, so the interval runs from 45.872 to 54.128. If were known, $z^* = 1.96$ would give a slightly narrower margin of 3.9199.
Proportion. In a survey, 81 of 263 people answer yes: 0.308. The 95 % Wilson interval is 0.2553 to 0.3662; the Wald interval, 0.2522 to 0.3638, is shifted slightly towards 0. With 0 successes out of 20, Wald collapses to the useless interval 0 to 0, while Wilson gives 0 to 0.1611.
Two means. Group 1: , , ; group 2: , , . The difference is 4 with standard error 2.234 and Welch degrees of freedom 62.73 ($t^* =$ 1.9985). The 95 % interval is 4 ± 4.46, from -0.46 to 8.46; it contains 0, so the data do not show a clear difference at this level.
What "95 % confidence" means — and what it does not
The 95 % describes the method, not one particular interval. If you repeated the study many times and built an interval each time, about 95 % of those intervals would contain the true mean or proportion. A single computed interval either contains it or not; you just don't know which.
It does not mean that 95 % of individual values fall in the interval — that is a prediction or tolerance interval, which is much wider. Nor does a wider interval mean a worse study: higher confidence always costs width. Going from 95 % to 99 % multiplies the margin by about for large samples.
To halve the margin of error you need four times as many observations, because the standard error shrinks with . The sample size calculator works this out in reverse, from the margin you want.
Why Wilson instead of Wald for proportions
The Wald interval is the one most textbooks show first, but Brown, Cai and DasGupta (2001) and Agresti and Coull (1998) showed that its true coverage is often far below the nominal 95 %, even with hundreds of observations, and especially when is near 0 or 1. It can also produce impossible bounds below 0 or above 1, or a zero-width interval when there are no successes.
The Wilson score interval inverts the score test instead. It is never wider than needed, always stays within 0 and 1, and its coverage stays close to the nominal level. The rule "at least 10 successes and 10 failures" is a quick check for when Wald becomes acceptable.
Frequently asked questions
How do I calculate a 95 % confidence interval?
Compute the standard error (s/√n for a mean), multiply it by the critical value (1.96 for z, or t with n − 1 degrees of freedom), and add and subtract the result from the sample estimate. The calculator does all three steps and shows them.
What is the margin of error?
It is the half-width of the interval: critical value × standard error. A poll reported as "52 % ± 3 points" has a margin of error of 3 percentage points, usually at 95 % confidence.
Should I use z or t?
Use t whenever the standard deviation is estimated from the same sample, which is almost always the case. z is for a population σ that is truly known, and for proportions. With more than a few hundred observations the two give practically the same interval.
Why is the Wilson interval not centred on p̂?
Wilson pulls the centre slightly towards 0.5, by the amount z²/2n. This compensates for the skewed sampling distribution of a proportion near 0 or 1 and is the reason its coverage is better than Wald’s.
What if the interval for a difference contains 0?
Then a difference of zero is plausible at that confidence level, which matches a two-sided t-test that does not reject equality at α = 1 − confidence. If 0 lies outside, the test would reject.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.2 Confidence limits for the mean
- Agresti A, Coull BA (1998), Approximate is better than “exact” for interval estimation of binomial proportions, The American Statistician 52(2):119–126
- Wilson EB (1927), Probable inference, the law of succession, and statistical inference, JASA 22(158):209–212
- Brown LD, Cai TT, DasGupta A (2001), Interval estimation for a binomial proportion, Statistical Science 16(2):101–133
- OpenStax, Introductory Statistics 2e, chapter 8: Confidence intervals
Last updated: