Confidence Interval Calculator
Find the confidence interval for a population mean from your sample data. Enter your values below, and see the formula, a worked example, and ready-to-use Python code underneath.
Enter your data
Separate values with commas, spaces, or new lines.
Please enter at least 2 values (and a valid σ, if using the known-σ option).
What a confidence interval tells you
A confidence interval gives a plausible range for a population mean, built from a sample, rather than a single point estimate. Instead of just saying "the average is 86.5," a confidence interval says something like "we're 95% confident the true average is between 82.2 and 90.8," which communicates the uncertainty in the estimate honestly.
The width of the interval depends on three things: how confident you want to be, how much the data varies, and how large your sample is. Larger samples and less variable data produce narrower, more precise intervals.
Confidence interval formula
Known σ (normal distribution): x̄ ± z₍α/2₎ · (σ / √n)
Python code
SciPy provides ready-made interval functions for both cases:
# Unknown population std dev — t-distribution from scipy import stats data = [78, 85, 92, 88, 76, 95, 89, 84, 91, 87] n = len(data) mean = sum(data) / n sem = stats.sem(data) # standard error of the mean ci = stats.t.interval(0.95, df=n - 1, loc=mean, scale=sem) print(ci) # (82.218, 90.782) # Known population std dev — normal distribution sigma = 6 sem_known = sigma / n ** 0.5 ci_known = stats.norm.interval(0.95, loc=mean, scale=sem_known)
Worked example
Ten students' exam scores: 78, 85, 92, 88, 76, 95, 89, 84, 91, and 87. Find the 95% confidence interval for the true average score, assuming the population standard deviation is unknown.
- 1Find the sample mean and standard deviation.
x̄ = 86.5, s = 5.9861, n = 10 - 2Find the standard error.
SE = 5.9861 / √10 = 1.8930 - 3Find the critical t-value.
For 95% confidence with df = 9, t = 2.2622 - 4Compute the margin of error and the interval.
MOE = 2.2622 × 1.8930 = 4.2822 → CI = 86.5 ± 4.2822
We're 95% confident the true average score lies between 82.22 and 90.78.
Frequently asked questions
What does a 95% confidence interval actually mean?
It means that if you repeated the sampling process many times and built a confidence interval the same way each time, about 95% of those intervals would contain the true population mean. It does not mean there's a 95% probability the true mean falls in this one specific interval.
Should I use the t-distribution or the normal (z) distribution?
Use the t-distribution whenever the population standard deviation is unknown and estimated from the sample, which is the case in most real analyses. Use the normal distribution only when the population standard deviation is genuinely known in advance.
Why does a higher confidence level produce a wider interval?
A higher confidence level requires more of the distribution to be captured, which needs a larger critical value and therefore a wider margin of error. There's a direct trade-off between how confident you want to be and how precise (narrow) the interval is.
How does sample size affect the confidence interval?
Larger samples produce narrower confidence intervals, because the standard error shrinks as sample size grows (it's divided by the square root of n). Quadrupling the sample size roughly halves the width of the interval, all else being equal.
Does the confidence interval assume the data is normally distributed?
The t-based confidence interval for a mean relies on the sampling distribution of the mean being approximately normal, which holds either if the underlying data is roughly normal, or if the sample is large enough for the central limit theorem to apply (often cited as n ≥ 30).