Confidence intervals
Quick answer
A confidence interval is a range calculated by a procedure designed to cover a fixed population parameter at a specified long-run rate under its assumptions. A 95% frequentist interval procedure covers the true parameter in about 95% of repeated samples when the model holds. It does not give a 95% probability that a fixed parameter lies in this particular observed interval.
Known versus estimated spread
For IID normal observations and known population standard deviation σ, a two-sided 95% z interval for the mean is mean ± 1.96 σ/sqrt(n), using an approximate critical value. For unknown σ and IID normal observations, use the Student t critical value with n−1 degrees of freedom and estimated standard error s/sqrt(n). The t critical value for 95% and 4 degrees of freedom is approximately 2.776. For [8, 9, 10, 11, 12], mean=10 and s²=2.5. A symmetric t interval is appropriate under the stated model; small samples with strong skew or dependence may not justify it.
from statistics import mean, stdevfrom math import sqrtx = [8, 9, 10, 11, 12]m = mean(x)margin = 2.776 * stdev(x)/sqrt(len(x))print(round(m-margin, 3), round(m+margin, 3))Expected output (local Python 3.13.5):
8.037 11.963The approximate 95% t interval is [8.037, 11.963]. The sample alone does not prove the assumptions.
Width depends on precision
In an ML latency benchmark, imagine an independently sampled population with known σ=4 ms and a measured mean of 20 ms. Increasing sample size from 16 to 64 halves the margin at fixed confidence level. Raising the confidence level at fixed data increases the critical value and the interval width. A confidence interval for the mean is not an interval expected to contain 95% of individual future latencies: prediction intervals address new observations and include their variation.
for n in [16, 64]: margin = 1.96 * 4 / n**0.5 print(n, round(20-margin, 2), round(20+margin, 2))Expected output (local Python 3.13.5):
16 18.04 21.9664 19.02 20.98The margin falls from 1.96 to 0.98 ms.
Common mistakes
Do not automatically use 1.96 with unknown variance in a tiny sample. Do not call the confidence level the probability of the fixed parameter after observing the interval. A narrow interval does not repair sampling bias, model misspecification or repeated benchmark tuning on the same test set.
Practice and next steps
For mean 12, SE 0.5 and supplied critical value 2.1, calculate the endpoints and explain the confidence level as a repeated-procedure property. Next, learn how resampling can estimate variability when a simple formula is unavailable.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Confidence intervals — knowledge check
Apply statistical reasoning to original synthetic examples.
What does a 95% confidence level refer to?
For unknown σ and small IID normal samples, which critical distribution is appropriate for a mean interval?
If center=10, SE=2 and c=3, what is the interval?
What happens to width when the critical value increases with SE fixed?
Which interval targets a new individual observation?