Learning outcomes
By the end of this lesson you should be able to: construct a confidence interval for a mean from a sample mean, a standard deviation and a sample size; construct one for a proportion; state the correct interpretation of a 95% confidence interval and reject the common misreadings; and explain how the confidence level and the sample size change the interval.
Prerequisites
Lessons 3 and 7 (Spread & shape, Sampling distributions & the CLT). You need the standard error of a mean and of a proportion, together with the normal distribution of lesson 6 to read the margin of error.
The big idea
A point estimate alone hides its own uncertainty. Reporting 'the mean commute is 28 minutes' sounds exact and is not; 'the mean commute is 28 minutes, with a 95% confidence interval of 24.08 to 31.92' gives the reader both the estimate and how much it could move. The interval is the honest unit of reporting for any estimate made from a sample.
The two-line recipe, and where it comes from
The recipe is short: estimate, plus or minus critical value times standard error. For a mean, the estimate is the sample mean, the SE is sigma over root n, and the critical value is the z that leaves the chosen tail probability outside — 1.96 for 95%. The numbers come from lesson 7: the sample mean is normally distributed around the population mean with a standard deviation equal to the SE, so an interval reaching two SEs on either side will contain the population mean about 95% of the time.
When sigma is unknown and replaced by the sample standard deviation, extra uncertainty enters and the t-distribution replaces the normal, with heavier tails that thin toward the normal as the degrees of freedom grow. For proportions the standard error takes its own form, the square root of p-hat times (1 - p-hat) divided by n, because the standard deviation of a yes/no variable depends on the proportion itself. In both cases the structure is identical: an estimate, a standard error and a critical value.
Worked example 1: a confidence interval for a mean
A sample of 36 commuters has a mean journey of 28 minutes and a standard deviation of 12. Build the 95% interval using sigma over root n and the z level of 1.96.
import math
n, xbar, s = 36, 28, 12
se = s / math.sqrt(n)
z = 1.96
moe = z * se
print("SE:", se)
print("margin of error:", round(moe, 2))
print("95% CI:", round(xbar - moe, 2), "to", round(xbar + moe, 2))SE: 2.0
margin of error: 3.92
95% CI: 24.08 to 31.92Method: SE = s / root n = 12 / 6 = 2, so the margin of error is 1.96 x 2 = 3.92, and the interval runs from 28 - 3.92 = 24.08 to 28 + 3.92 = 31.92. Reading it: the procedure that produced this interval captures the true mean in about 95 out of every 100 repetitions of the sampling-and-interval routine. In practice sigma is unknown, so s stands in for it and a t level with 35 degrees of freedom would be used instead of 1.96, giving a slightly wider interval because estimating the standard deviation costs precision.
Worked example 2: what the confidence level does
The same data at three confidence levels. A higher level buys certainty by widening the interval; there is no free lunch.
import math
n, xbar, s = 36, 28, 12
se = s / math.sqrt(n)
for level, z in [(0.90, 1.645), (0.95, 1.96), (0.99, 2.576)]:
moe = z * se
print(f"{int(level * 100)}% CI: {xbar - moe:.2f} to {xbar + moe:.2f} (margin {moe:.2f})")90% CI: 24.71 to 31.29 (margin 3.29)
95% CI: 24.08 to 31.92 (margin 3.92)
99% CI: 22.85 to 33.15 (margin 5.15)Method: with SE = 2, the margins are 1.645 x 2 = 3.29, 1.96 x 2 = 3.92 and 2.576 x 2 = 5.152, giving total widths of 6.58, 7.84 and 10.30. The extra certainty from 95% to 99% costs an extra 1.23 minutes of width on each side. Only the sample size improves both at once — a larger n shrinks the SE, and with the level held fixed the interval tightens around the same point estimate.
Watch outThe most common misreading of a 95% interval is 'there is a 95% probability that the true mean lies between 24.08 and 31.92'. Once the interval is computed, the mean is either inside it or not; the 95% is a property of the procedure over repeated samples, not of this one interval.
Worked example 3: a confidence interval for a proportion
In a poll of 100 voters, 60 support a candidate. The standard error of a proportion is computed from p-hat itself, and the success-failure condition of lesson 6 gates the method.
import math
n, phat = 100, 0.6
se = math.sqrt(phat * (1 - phat) / n)
moe = 1.96 * se
print("p-hat:", phat)
print("SE:", round(se, 4))
print("95% CI:", round(phat - moe, 4), "to", round(phat + moe, 4))
print("success count:", int(n * phat), "failure count:", int(n * (1 - phat)))p-hat: 0.6
SE: 0.049
95% CI: 0.504 to 0.696
success count: 60 failure count: 40Method: the SE of a proportion is the square root of p-hat times (1 - p-hat) divided by n, which is the square root of 0.6 x 0.4 / 100 = 0.0024, giving 0.049. The margin is 1.96 x 0.049 = 0.096, so the interval runs from 0.504 to 0.696 — a poll with a 60% headline is really saying somewhere between 50% and 70%. The gate is the success-failure condition: n p-hat = 60 and n(1 - p-hat) = 40, both at least 10, so the normal model applies. With only 10 respondents and 3 successes, that check would fail and the interval would be worthless.
| Sample size n | SE of a proportion near 0.5 | 95% margin of error |
|---|---|---|
| 100 | 0.050 | +/- 0.098 |
| 400 | 0.025 | +/- 0.049 |
| 1000 | 0.016 | +/- 0.031 |
| 2500 | 0.010 | +/- 0.020 |
Method: for a proportion near one half, the SE is about 0.5 / root n, so the 95% margin is roughly 1 / root n. That is why a poll of 1000 has a margin near 3 percentage points and a poll of 2500 near 2 points — and why halving the margin costs four times the sample.
Common mistakes
Watch outReading the interval as '95% of the data lies in this range'. The interval is about the population parameter, not about individual observations — individual commutes spread far wider than 24.08 to 31.92 minutes.
Watch outUsing the normal critical value when sigma is estimated and n is small. The t level is wider; ignoring the difference makes the interval too narrow and the confidence overstated, which is why the t-distribution exists.
Watch outBuilding a proportion interval without the success-failure check. If fewer than 10 successes or 10 failures are expected, the normal model does not apply and the interval is not trustworthy.
Watch outChasing a narrower interval by lowering the confidence level instead of collecting more data. The honest route to precision is a bigger sample; dropping to 50% confidence to make an interval look tight misrepresents the uncertainty.
Check your understanding
A 95% confidence interval for the mean commute is 24.08 to 31.92 minutes. What does '95% confident' actually mean?
For the same data, how does the margin of error change if the sample size grows from 36 to 144?
In a poll of 100 voters with 60 in support, why does the standard error use 0.6 x 0.4?
Multiple choice
A sample of 36 items has s = 12. What is the standard error of the mean?
Which is the correct interpretation of a 95% confidence interval of 28 to 36 minutes?
Holding the data fixed, what happens when you raise the confidence level from 95% to 99%?
A proportion interval from a sample of 20 voters with 5 successes is reported as 0.25 plus or minus 0.19. Why is that interval unreliable?
A 95% interval for a proportion is 0.504 to 0.696 from a sample of 100 with p-hat 0.6. By roughly what factor must the sample size grow to halve the margin of error?
Summary and next
A confidence interval is a point estimate plus and minus a critical value times a standard error. For a mean, SE = sigma over root n with the normal level 1.96 at 95% — a t level when sigma is estimated; for a proportion, SE = the square root of p-hat times (1 - p-hat) over n, gated by the success-failure condition. Higher confidence means a wider interval, and only a bigger sample improves both at once. The 95% figure belongs to the procedure across repetitions, not to any single interval.
Next: hypothesis testing. A confidence interval reports a range of plausible values; a test asks a sharper question — is a specific value of the parameter compatible with the data? The machinery is nearly the same, and the reasoning about what the answer means is where most errors are made.