A survey finds that 42% of 1,000 customers prefer the new packaging. A sample of 36 deliveries averages 50 minutes. These numbers are estimates: ask a different 1,000 customers or time a different 36 deliveries, and you would get slightly different results. A confidence interval turns a single estimate into a range that honestly reflects that sampling uncertainty, such as "42%, give or take about 3 percentage points".
This guide explains what a confidence interval does and does not mean, walks through the calculation for a mean and for a proportion, shows when to use the t-distribution instead of z, and explains why the Wilson interval is preferred for proportions, especially with small samples or rare outcomes.
The general shape of a confidence interval
Almost every interval you will meet has the same structure:
estimate ± critical value × standard error
- The estimate is your sample mean or sample proportion.
- The standard error (SE) measures how much that estimate would typically vary from sample to sample.
- The critical value sets the confidence level: about 1.96 for 95% with the normal distribution.
- The product, critical value × SE, is the margin of error.
What "95% confident" actually means
A 95% confidence interval comes from a procedure that, if you repeated the sampling many times, would capture the true value in about 95% of the intervals it produced. It is a statement about the reliability of the method.
It does not mean there is a 95% probability that the true value lies inside this particular interval, strictly speaking, and it does not mean 95% of individual values fall inside it. The interval is about the population mean or proportion, not about individual data points. That second misreading is especially common: a 95% interval for the average delivery time says nothing about how long any single delivery takes.
Confidence interval for a mean
The t interval (σ unknown)
In practice you rarely know the population standard deviation σ. You estimate it with the sample standard deviation s, and that extra uncertainty is handled by using the t-distribution with n − 1 degrees of freedom:
x̄ ± t* × s ÷ √n
Example. A sample of n = 36 deliveries has mean x̄ = 50 minutes and standard deviation s = 8 minutes.
- Standard error: 8 ÷ √36 = 8 ÷ 6 ≈ 1.333
- Critical value for 95% with 35 degrees of freedom: t* ≈ 2.030
- Margin of error: 2.030 × 1.333 ≈ 2.71
- Interval: 50 ± 2.71, or about 47.29 to 52.71 minutes
The z interval (σ known)
If σ is genuinely known, for example from a long-established process, use z* instead of t*. With σ = 8, the 95% critical value is 1.960, the margin is 2.61, and the interval is 47.39 to 52.61. It is slightly narrower because there is less uncertainty.
How t compares with z
The t critical value is larger for small samples and approaches 1.96 as the sample grows:
| Degrees of freedom | 95% t* |
|---|---|
| 5 | 2.571 |
| 10 | 2.228 |
| 30 | 2.042 |
| 100 | 1.984 |
| (normal) | 1.960 |
With small samples, using z instead of t makes the interval too narrow and overstates your precision.
What makes an interval wider or narrower
- Confidence level. Higher confidence needs a wider net. For the delivery data, the 99% t interval is 50 ± 3.63, compared with ± 2.71 at 95%.
- Sample size. The standard error shrinks with √n, so quadrupling the sample roughly halves the margin. With n = 144 instead of 36, the 95% margin drops from 2.71 to about 1.32.
- Variability. Noisier data (a larger s) widen the interval in direct proportion.
Confidence interval for a proportion
For a proportion p̂ = x ÷ n (successes over sample size), the textbook formula is the Wald interval:
p̂ ± z* × √(p̂(1 − p̂) ÷ n)
Example. 420 of 1,000 customers prefer the new packaging: p̂ = 0.42.
- Standard error: √(0.42 × 0.58 ÷ 1000) ≈ 0.0156
- Margin of error: 1.96 × 0.0156 ≈ 0.0306, about 3.1 percentage points
- Wald interval: 38.9% to 45.1%
Why the Wilson interval is better
The Wald interval behaves badly when n is small or p̂ is close to 0% or 100%. It can extend below 0 and, when there are zero successes, it collapses to a width of zero, suggesting perfect certainty.
The Wilson score interval fixes this by shifting the centre slightly towards 50% and adjusting the width. For large samples like the one above, the two agree closely (Wilson gives 38.98% to 45.08%). For small samples they do not:
| Data | Wald 95% | Wilson 95% |
|---|---|---|
| 3 defects in 40 items | 0% to 15.7% (cut off at 0) | 2.6% to 19.9% |
| 0 defects in 20 items | 0% to 0% | 0% to 16.1% |
Seeing zero defects in 20 items does not prove the defect rate is zero; the Wilson interval honestly says it could plausibly be as high as 16%. Many statisticians recommend Wilson as the default for proportions.
Sample size for a target margin
Rearranging the proportion formula gives the sample needed for a desired margin of error, using p = 0.5 as the worst case:
n = z*² × 0.25 ÷ margin²
For ±3 percentage points at 95%: 1.96² × 0.25 ÷ 0.03² ≈ 1,067. For ±5 points, about 385. This is why many opinion polls interview roughly a thousand people.
Using the confidence interval calculator
The Confidence Interval Calculator covers all three cases.
- Choose the type: Mean, σ unknown (t), Mean, σ known (z) or Proportion.
- Pick a Confidence level: 80%, 90%, 95%, 98%, 99%, 99.9% or Custom….
- For a mean, choose Summary statistics (enter the Sample mean, the standard deviation and the Sample size) or Raw data (paste the Sample values and the tool computes the mean and s for you).
- For a proportion, enter the Successes (x) and the Sample size (n).
- Read the interval, plus the point estimate ± margin, the critical value, the standard error and, for t intervals, the z* value for comparison.
For proportions, the headline result is the Wilson interval, with the Wald interval and its margin of error shown underneath so you can compare. The tool adds a note when n·p̂ or n·(1 − p̂) is below 10, the usual sign that the Wald interval is unreliable.
Other ways to calculate intervals
- Spreadsheets:
=CONFIDENCE.T(0.05, s, n)returns the t margin of error for a mean, and=CONFIDENCE.NORM(0.05, sigma, n)the z margin. There is no built-in Wilson function, so proportions need a manual formula. - Statistical software such as R (
t.test,prop.test, which uses a Wilson-type interval) and Python's SciPy or statsmodels libraries. - By hand with a t-table, which is fine for coursework once you know the degrees of freedom.
To convert between probabilities and critical values, use the Z-Score Calculator; for the standard deviation of raw data, the Standard Deviation Calculator; and for comparing two conversion rates, the A/B Test Calculator.
Common mistakes
- Using z with a small sample and an estimated standard deviation. Use t.
- Reading the interval as a range for individual values. It describes the mean or proportion, not single observations.
- Ignoring bias. An interval only captures sampling error. A survey sent only to loyal customers can produce a narrow interval around the wrong answer.
- Comparing overlapping intervals as a significance test. Two 95% intervals can overlap slightly while the difference between groups is still statistically significant; test the difference directly.
Frequently asked questions
What is the margin of error?
It is half the width of the confidence interval: the critical value times the standard error. A result of 42% ± 3.1 points has a margin of error of 3.1 percentage points.
Should I use a t or z confidence interval?
Use t when you estimate the standard deviation from the sample, which is almost always. Use z only when the population standard deviation is genuinely known, or for proportions.
Why does a larger sample give a narrower interval?
The standard error is the standard deviation divided by √n, so more data reduce the uncertainty in the estimate. Doubling precision needs about four times the sample.
Is a 99% confidence interval better than a 95% one?
It is more likely to contain the true value, but it is wider and therefore less precise. The 95% level is a common compromise, not a rule.
What is the Wilson interval?
A method for proportion confidence intervals that stays within 0% to 100% and behaves well with small samples or extreme proportions, unlike the simpler Wald interval.