Confidence Intervals

Draw 100 samples, build an interval from each and count how many capture the true mean

Intermediate
Interval

The last 100 intervals, newest at the top(blue captures μ, red misses; dot = x̄)

true mean μ = 10071.581.090.5100.0109.5119.0128.5Draw a sample to build its interval

Running coverage

50%60%70%80%90%100%nominal 95%samples drawn
Population

Normal with μ = 100 and σ = 15. Each sample is n = 10 values; standard error σ/√n = 4.743.

Coverage
Samples
0
Captured μ
0
Coverage
–
Nominal
95%
Margin of error

E = z* × σ/√n

= 1.960 × 15.00/√10 = 9.297

z* (95%)
1.960
t* with 9 df
2.262
Last interval

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

Every interval has the same shape: a point estimate (the sample mean) plus and minus a margin of error.

The method has the confidence

A 95% method captures μ in about 95% of repeated samples. Any single interval either contains μ or it does not.

Wider for more confidence

A higher confidence level needs a larger critical value, so the interval gets wider. You trade precision for certainty.

Narrower with more data

The margin shrinks like 1/√n. To halve it you need four times as many observations.

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

Two-sided critical values. The t columns use n − 1 = 4, 9 and 29 degrees of freedom.
Confidencez*t*, n = 5t*, n = 10t*, n = 30
80%1.2821.5331.3831.311
90%1.6452.1321.8331.699
95%1.9602.7762.2622.045
99%2.5764.6043.2502.756

How to use this visualizer

  1. 1
    Pick a sample size n and a confidence level. The population is normal with μ = 100 and σ = 15, shown as the purple line.
  2. 2
    Press Draw 1 sample. The dot is the sample mean and the bar is its interval: blue if it captures μ, red if it misses.
  3. 3
    Press Draw 100 or Auto-draw and watch the running coverage settle near the nominal level (the dashed line).
  4. 4
    Move 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.
  5. 5
    Switch to the t interval. Now each interval uses its own s, so the widths vary, but coverage still matches the nominal level.
  6. 6
    Try "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

A sample of 36 bulbs has a mean lifetime of 1200 hours. The population standard deviation is known to be 90 hours. Build a 95% confidence interval for the mean lifetime. How many bulbs would you need for a margin of error of 10 hours?
Show 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

Sixteen people take a reaction test. Their mean time is 4.2 tenths of a second with sample standard deviation s = 0.8. Build a 95% t interval for the mean, and compare its margin with the one you would get by wrongly using z*.
Show 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

Discussion

Questions, ideas or a different approach? Join the conversation.