Confidence Intervals, Explained
After reading this you can build and read a confidence interval for a mean, a proportion, or a standard deviation, pick the right method, and avoid the errors that turn a correct interval into a misleading one.
What a confidence interval tells you
A confidence interval is a range built from your data that is designed to cover the unknown population value at a stated rate over many repeated samples. The stated rate is the confidence level, usually 95%.
Here is the hook. Suppose you measure the fill volume of 25 bottles and get a sample mean of 50 ml with a sample standard deviation of 10 ml. The 95% t interval for the true mean is 50 ± 4.128, that is 45.87 to 54.13 ml. The single best guess is 50, but the data are consistent with any true mean between about 46 and 54.
The interval width, 8.256 ml here, is the honest statement of how much the mean could move if you sampled again. A point estimate alone hides that uncertainty.
The 95% refers to the procedure, not to one interval. If you repeated the whole study many times, about 95% of the intervals you build would contain the true value. Any single interval either contains it or does not.
When to use each mode
This calculator covers four situations. Match the mode to your data.
- Mean, sample sd (t interval)
- You have continuous data, you estimated the standard deviation from the sample, and you want the mean. This is the common case. Use it whenever you computed
sfrom your own numbers. - Mean, known σ (z interval)
- You want the mean and the population standard deviation is genuinely known ahead of time, for example from a long production history. This is rare in practice.
- Proportion
- Your data are yes or no, and you want the fraction of yeses. You supply the number of successes and the sample size.
- Standard deviation (χ² interval)
- You want a range for the spread itself, not the mean. This assumes the data are normally distributed, and it is sensitive to that assumption.
Do not use a confidence interval to describe where individual observations fall. That is a prediction interval or a tolerance interval, and it is much wider. A 95% confidence interval for the mean answers a question about the mean, not about a single new bottle.
The formulas and the intuition
Every interval here has the same shape: estimate, plus or minus a critical value times a standard error.
This is the t interval for a mean. \bar{x} is the sample mean, s is the sample standard deviation, n is the sample size, and t_{n-1,\, 1-\alpha/2} is the critical value from the t distribution with n-1 degrees of freedom. The term s/\sqrt{n} is the standard error of the mean: it shrinks as n grows, which is why bigger samples give tighter intervals.
The z interval replaces t with a standard normal quantile z_{1-\alpha/2} and uses the known \sigma instead of s. For 95% confidence, z = 1.960. The t value is always a little larger because estimating s adds uncertainty. At n=25 the t value is 2.064.
This is the Wald interval for a proportion, where \hat{p} is successes divided by n. It is simple but poor when \hat{p} is near 0 or 1, or when n is small. The Wilson interval corrects that by centering the interval differently:
The Wilson interval pulls the center toward 0.5 and never runs below 0 or above 1. Prefer it in almost every proportion problem.
Worked example with the demo data
A 95% t interval for the mean
Use the calculator defaults: mode t interval, level 95, n=25, mean 50, sd 10.
- Standard error: s/\sqrt{n} = 10/\sqrt{25} = 10/5 = 2.000.
- Degrees of freedom: n-1 = 24.
- Critical value: t_{24,\,0.975} = 2.064.
- Margin of error: 2.064 \times 2.000 = 4.128.
- Interval: 50 \pm 4.128, that is
45.87to54.13.
Now compare methods and levels for the same data. Notice how the z interval is slightly narrower than the t interval, and how 99% confidence widens the range.
| Method | Level | Critical value | Margin | Lower | Upper |
|---|---|---|---|---|---|
| t | 90% | 1.711 | 3.422 | 46.58 | 53.42 |
| t | 95% | 2.064 | 4.128 | 45.87 | 54.13 |
| t | 99% | 2.797 | 5.594 | 44.41 | 55.59 |
| z | 95% | 1.960 | 3.920 | 46.08 | 53.92 |
A worked proportion, both ways
3 successes in 20 trials
Set mode to proportion, n=20, successes 3, level 95. Then \hat{p} = 0.15 and z = 1.960.
- Wald standard error: \sqrt{0.15 \times 0.85 / 20} = \sqrt{0.006375} = 0.07984.
- Wald margin: 1.960 \times 0.07984 = 0.1565, giving
-0.0065to0.3065. - The Wald lower bound is negative, which is impossible for a proportion. That is the Wald failure near the boundary.
- The Wilson interval for the same data is
0.0524to0.3607, entirely inside [0, 1].
Use Wilson. With small samples or proportions near 0 or 1, Wald can produce impossible or too narrow intervals.
Reading and interpreting the result
Say the correct sentence. For the demo mean interval: "with 95% confidence, the true mean fill volume is between 45.87 and 54.13 ml." That describes the procedure's long-run coverage.
Avoid the wrong sentence: "there is a 95% probability the mean is in this interval." Once the interval is computed, the mean is either in it or not; the 95% describes the method across many samples, not this one number.
Two practical readings follow from the width. First, if the interval is too wide to be useful, you need more data; recall that halving the margin takes four times the sample size. Second, if the interval excludes a value of interest, say a target of 60 ml, that is evidence against the mean being 60. The demo interval 45.87 to 54.13 excludes 60, so 60 is implausible at the 5% level.
A 95% interval that excludes a specific value corresponds to a two-sided test rejecting that value at \alpha = 0.05. The interval and the test agree by construction.
Common mistakes
These errors are frequent and each one changes the numbers.
- Using z when you estimated the standard deviation. At n=25 the z margin is
3.920but the correct t margin is4.128. The z interval is too narrow, so it overstates precision. Use z only for a truly known \sigma. - Wald near the boundary. As shown above, Wald gave a negative lower bound. Prefer Wilson for proportions.
- Confusing the standard deviation with the standard error. The sd is
10; the standard error is2. The interval uses the standard error. Dividing by \sqrt{n} is the step people skip. - Treating the χ² interval as symmetric. The interval for a standard deviation is skewed. For n=25 and s=10, the 95% interval runs about
7.81to13.91, wider on the high side. Do not write it as s \pm something. - Assuming normality without checking. The t interval is robust for large
n, but the χ² interval for the sd is not; heavy tails or skew break it.
Related tools
To plan a study rather than analyze one, use the Sample Size Calculator to find the n that hits a target margin of error. For designs framed around detecting a difference, the Power and Sample Size for t-Tests calculator gives the n for a chosen power.
When you report a difference between groups, pair the interval with an effect size from the Cohen's d Effect Size Calculator, and convert between measures with the Effect Size Converter.
Frequently asked questions
Why is my t interval wider than the z interval?
Because the t distribution has heavier tails to account for estimating the standard deviation from the sample. At n=25 the 95% multipliers are 2.064 for t versus 1.960 for z. As n grows the two converge; by n=1000 the t value is about 1.962.
What confidence level should I use?
95% is the default convention. Choose 90% if a narrower interval is acceptable and you can tolerate lower coverage, or 99% when a missed value is costly. Higher confidence means a wider interval: for the demo data the margin grows from 3.422 at 90% to 5.594 at 99%.
Should I ever use the Wald interval for a proportion?
Only when n is large and \hat{p} is well away from 0 and 1, roughly when both n\hat{p} and n(1-\hat{p}) exceed about 10. Otherwise use Wilson, which stays inside [0, 1] and has better coverage.
How do I halve my interval width?
Collect four times as much data, since the margin scales with 1/\sqrt{n}. Going from n=25 to n=100 cuts the demo margin from 4.128 to 1.984.
Can a confidence interval contain impossible values?
The Wald proportion interval can, as in the example where the lower bound was -0.0065. That is a signal the method is wrong for the data, not a real possibility. The Wilson and χ² intervals are constructed to respect their natural bounds.