How to Calculate a Confidence Interval
A confidence interval (CI) provides a range of plausible values for an unknown population parameter—such as a true population mean (μ) or population proportion (p)—constructed around your observed sample estimate plus and minus a Margin of Error (E).
Mean Confidence Interval Formula
Using Student's t-distribution (or Z when σ is known)
Where x̄ is the sample mean, s is sample standard deviation, n is sample size, and t* is the critical value for df = n − 1 degrees of freedom (replace t* and s with z* and σ when population σ is known).
Proportion Confidence Interval Formula
Normal approximation (Wald Z-interval)
Where p̂ = x / n is the sample proportion of successes, n is total sample size, and z* is the standard normal critical value (e.g., 1.9600 for 95% confidence).
Concrete Worked Example (95% t-Confidence Interval)
Suppose an engineer tests n = 25 EV battery packs and measures a sample mean lifespan of x̄ = 48.0 months with a sample standard deviation of s = 5.0 months. Find the 95% confidence interval:
Find Critical Value (t*): Since population σ is unknown, use the t-distribution with df = 25 − 1 = 24. At 95% confidence (two-tailed α = 0.05), t* = 2.0639.
Compute Standard Error (SE): Divide standard deviation by √n → SE = 5.0 ÷ √25 = 5.0 ÷ 5 = 1.0000.
Calculate Margin of Error (E): Multiply critical value by SE → E = 2.0639 × 1.0000 = 2.0639.
Construct Interval [x̄ − E, x̄ + E]: Lower = 48.0 − 2.0639 = 45.9361; Upper = 48.0 + 2.0639 = 50.0639 → [45.9361, 50.0639].
Z-Distribution vs. t-Distribution: When to Use Which?
Choosing between a Z-interval and a t-interval depends primarily on whether you know the true population standard deviation (σ) or estimate dispersion from your sample (s):
| Criterion | Z-Distribution (Standard Normal) | t-Distribution (Student's t) |
|---|---|---|
| Population Std Dev (σ) | Known (from historical census, calibration spec, or theoretical variance) | Unknown — estimated using sample standard deviation (s) |
| Degrees of Freedom (df) | Not required (fixed standard normal curve) | Required: df = n − 1 (curve shape adapts to sample size) |
| Tail Behavior | Thinner tails; narrower interval for small samples | Heavier tails to account for extra uncertainty in estimating s; converges to Z as n grows large |
| 95% Critical Value | Always z* = 1.9600 | t* = 2.2622 (at n=10), 2.0452 (at n=30), 1.9842 (at n=100) |
| Best Practical Use Cases | Population proportions / percentages, quality control with known σ, very large samples | Almost all real-world sample means, raw experimental datasets, clinical & academic studies |
Frequently Asked Questions
s)—which is true in nearly all real-world datasets and raw measurements, especially when n < 30. Use the Z-distribution only when the true population standard deviation (σ) is known beforehand, or when calculating standard confidence intervals for proportions/percentages.
n) decreases the margin of error, making your confidence interval narrower and more precise. Because standard error divides by the square root of sample size (SE = s / √n), there are diminishing returns: to cut your margin of error in half, you need to multiply your sample size by four (since √4 = 2).
Explore Our Free Calculator Series
Fast, privacy-first math & statistical utilities running 100% in your browser.