Confidence Intervals
Draw 100 samples, build an interval from each and count how many capture the true mean
The last 100 intervals, newest at the top(blue captures μ, red misses; dot = x̄)
Running coverage
Normal with μ = 100 and σ = 15. Each sample is n = 10 values; standard error σ/√n = 4.743.
- Samples
- 0
- Captured μ
- 0
- Coverage
- –
- Nominal
- 95%
E = z* × σ/√n
= 1.960 × 15.00/√10 = 9.297
- z* (95%)
- 1.960
- t* with 9 df
- 2.262
No samples yet.
Changing the confidence level or interval type rebuilds the intervals from the same samples. Changing n starts over.
What a confidence interval is
You want the mean μ of a population, but you only have a sample of n values. The sample mean x̄ is your best single guess, yet it is almost never exactly right. A confidence interval adds a margin of error around x̄ to give a range of plausible values for μ.
The margin is a critical value times the standard error. The standard error σ/√n measures how much x̄ varies from sample to sample. The critical value sets the confidence level: for 95%, z* = 1.960 because 95% of a standard normal lies between −1.960 and 1.960.
When σ is unknown, which is the usual case, you replace it with the sample standard deviation s. That adds extra uncertainty, so the critical value comes from the t distribution with n − 1 degrees of freedom, whose heavier tails give a slightly wider interval. For large n the t and z critical values become almost the same.
Estimate ± margin
The method has the confidence
Wider for more confidence
Narrower with more data
Key formulas
z interval (σ known)
x̄ ± z* · σ / √n
- x̄
- sample mean
- z*
- standard normal critical value, e.g. 1.960 for 95%
- σ / √n
- standard error of the mean
t interval (σ unknown)
x̄ ± t*(n − 1) · s / √n
- s
- sample standard deviation
- t*
- t critical value with n − 1 degrees of freedom
Sample size for a target margin E
n = (z* · σ / E)², rounded up
Critical values
| Confidence | z* | t*, n = 5 | t*, n = 10 | t*, n = 30 |
|---|---|---|---|---|
| 80% | 1.282 | 1.533 | 1.383 | 1.311 |
| 90% | 1.645 | 2.132 | 1.833 | 1.699 |
| 95% | 1.960 | 2.776 | 2.262 | 2.045 |
| 99% | 2.576 | 4.604 | 3.250 | 2.756 |
How to use this visualizer
- 1Pick a sample size n and a confidence level. The population is normal with μ = 100 and σ = 15, shown as the purple line.
- 2Press Draw 1 sample. The dot is the sample mean and the bar is its interval: blue if it captures μ, red if it misses.
- 3Press Draw 100 or Auto-draw and watch the running coverage settle near the nominal level (the dashed line).
- 4Move the confidence level slider. The same samples are rebuilt with a new critical value, so you can watch the intervals widen and the red ones turn blue.
- 5Switch to the t interval. Now each interval uses its own s, so the widths vary, but coverage still matches the nominal level.
- 6Try "z with s" at n = 3 or 5. Its intervals are too narrow and coverage drops well below the nominal level, which is why the t distribution exists.
Common misconception
A 95% confidence interval of [96.2, 104.1] does not mean there is a 95% probability that μ lies in it. μ is a fixed number and this particular interval either contains it or not. The 95% describes the method: if you repeated the sampling many times, about 95% of the intervals built this way would contain μ. That is exactly what the coverage counter measures.Practice problems
Problem 1: Bulb lifetimes
Show solutionHide solution
SE = σ/√n = 90/√36 = 90/6 = 15 hours
E = z* · SE = 1.960 × 15 = 29.4 hours
Interval: 1200 ± 29.4 = [1170.6, 1229.4]
For E = 10: n = (1.960 × 90 / 10)² = 17.64² = 311.2, round up to 312
95% CI ≈ [1170.6, 1229.4] hours; n = 312 bulbs
Problem 2: Reaction times with σ unknown
Show solutionHide solution
SE = s/√n = 0.8/√16 = 0.8/4 = 0.2
Degrees of freedom: n − 1 = 15, so t* = 2.131
E = 2.131 × 0.2 = 0.426, interval 4.2 ± 0.426 = [3.774, 4.626]
With z* = 1.960: E = 1.960 × 0.2 = 0.392, which is about 8% too narrow
95% CI ≈ [3.77, 4.63]; the z margin (0.392) understates the uncertainty
Related topics
PDF and CDF
Critical values like z* = 1.960 are quantiles: points where the CDF reaches 0.975.
Law of Large Numbers
Why the running coverage settles on the confidence level as the number of samples grows.
Type I & II Errors and Power
The misses in this visualizer are the same 5% that a test calls Type I errors.
Discussion
Questions, ideas or a different approach? Join the conversation.