Confidence Interval Formula: How to Calculate
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator computes a confidence interval for a population mean when the population standard deviation is known. You enter the sample mean, sample size, population standard deviation, and desired confidence level; the calculator returns the lower and upper bounds of the interval. The general formula is: CI = x̄ ± z* × (σ / √n), where x̄ is the sample mean, z* is the critical z-value for the chosen confidence level, σ is the population standard deviation, and n is the sample size.
Formula
The general formula for a confidence interval for a population mean (when σ is known) is:
CI = x̄ ± z* × (σ / √n)
Where:
- x̄ (sample mean) – the average of your sample, in the same units as your data.
- z* (critical z-value) – the number of standard deviations from the mean that captures the central probability equal to your confidence level. For 90% it is 1.645, for 95% it is 1.960, for 99% it is 2.576.
- σ (population standard deviation) – the true spread of the entire population, in the same units as your data.
- n (sample size) – the number of observations in your sample.
The term z* × (σ / √n) is called the margin of error. The interval is centered at the sample mean and extends equally far above and below it.
Worked Example
Using the default values from the calculator: sample mean = 50, population SD = 10, sample size = 30, confidence level = 95% (z* = 1.960).
- Calculate the standard error: σ / √n = 10 / √30 = 10 / 5.477 = 1.8257.
- Multiply by the critical value: 1.960 × 1.8257 = 3.5784.
- Lower bound = 50 – 3.5784 = 46.42.
- Upper bound = 50 + 3.5784 = 53.58.
The 95% confidence interval is 46.42 to 53.58. The calculator shows the same result, rounding to two decimal places.
When to Use This Formula
This z-based formula applies when you know the population standard deviation (σ). That is rare in real research – you usually only have a sample. If σ is unknown, you should use the t-distribution instead, which gives a slightly wider interval to account for the extra uncertainty of estimating σ from the sample. The z-formula is still commonly taught as the foundation, and it works well when the sample size is large (n ≥ 30) even if σ is estimated, because the t-distribution approaches the normal distribution as n grows.
The formula also assumes:
- The sample is randomly drawn from the population.
- The observations are independent of each other.
- The population distribution is approximately normal, or the sample size is large enough for the Central Limit Theorem to apply (typically n ≥ 30).
If these assumptions are badly violated, the interval may not have the stated confidence level.
How to Read the Result
A 95% confidence interval does not mean there is a 95% chance that the true mean lies inside this particular interval. The true mean is fixed – it either is in the interval or it isn’t. The correct interpretation is: if you repeated the sampling process many times and calculated a 95% confidence interval each time, about 95% of those intervals would contain the true mean. For a single interval, you can say you have 95% confidence that it captures the true mean, but that is a statement about the method, not a probability about this specific interval.
The width of the interval tells you about precision:
- Narrower interval = more precise estimate.
- Wider interval = less precise estimate.
Precision improves with a larger sample size (because √n grows) and with a lower confidence level (because z* shrinks).
Common Mistakes and Misconceptions
- Confusing σ and s: The formula uses the population standard deviation σ. If you only have the sample standard deviation s, use the t-interval instead, unless n is large enough that the difference is negligible.
- Misinterpreting the confidence level: As noted above, 95% confidence is about the procedure, not the probability that the true mean is in a given interval.
- Ignoring the sample size: A tiny sample with a wide σ gives a huge margin of error. The formula correctly reflects that, but people sometimes expect a narrow interval from a small sample.
- Using the wrong critical value: For a 90% interval, z* is 1.645, not 1.28 (which is the one-tailed value). Always use the two-tailed critical value for a confidence interval.
- Rounding too early: Round the margin of error only at the end. Rounding σ/√n to two decimals before multiplying can change the final interval noticeably.
Alternatives and Related Formulas
When the population standard deviation is unknown, the general formula becomes:
CI = x̄ ± t* × (s / √n)
where t* is the critical t-value with n–1 degrees of freedom, and s is the sample standard deviation. This is the more common practical formula.
Other related intervals include:
- Proportion interval: For a population proportion p, the formula is p̂ ± z* × √(p̂(1–p̂)/n).
- Difference of means: For comparing two groups, the interval uses the difference of sample means and a pooled or separate standard error.
- Prediction interval: A wider interval that predicts a single future observation, not the mean.
- Bootstrap interval: A nonparametric method that resamples the data to estimate the sampling distribution, useful when the normal assumption fails.
Frequently Asked Questions
What is the difference between a confidence interval and a margin of error?
The margin of error is the half-width of the interval – the amount you add and subtract from the sample mean. For the z-formula, it is z* × (σ/√n). The confidence interval is the full range from (x̄ – margin) to (x̄ + margin).
Why is the z-value 1.96 for 95% confidence?
Because in a standard normal distribution, 95% of the area lies between z = –1.96 and z = +1.96. That leaves 2.5% in each tail. The value 1.96 is the two-tailed critical value that captures the central 95% of the distribution.
Can I use this formula for any sample size?
Technically, the formula relies on the Central Limit Theorem, which works well for n ≥ 30 even if the population is not normal. For smaller samples, the population should be approximately normal. If you have a small sample from a skewed distribution, consider a nonparametric method or a bootstrap.
What if I don’t know the population standard deviation?
Use the t-distribution with s (sample standard deviation) instead of σ. The t-interval is wider, reflecting the extra uncertainty. For large n (roughly > 30), the t and z values are nearly identical, so many practitioners use z as an approximation.
Does a wider interval mean a better estimate?
No. A wider interval is less precise. It does have a higher chance of containing the true mean, but that comes at the cost of usefulness. A narrow interval at the same confidence level is better because it pinpoints the mean more tightly.