How to calculate a confidence interval
To calculate a confidence interval, take your estimate and add and subtract the margin of error: a critical value for your confidence level times the standard error.[1]
mean: x̄ ± t* × s ÷ √n · proportion: p̂ ± z* × √(p̂(1 − p̂) ÷ n)t* has n − 1 degrees of freedom. Use z* instead of t* only when the population SD σ is known.
Worked example: a mean
n = 30, x̄ = 74.2, s = 8.5, 95% confidence. Standard error = 8.5 ÷ √30 = 1.5519. With 29 degrees of freedom, t* = 2.0452.[5]
Margin of error = 2.0452 × 1.5519 = 3.174. Interval: 74.2 ± 3.17 = 71.03 to 77.37.
Worked example: a proportion
540 of 1,000 people said yes, so p̂ = 0.54. Standard error = √(0.54 × 0.46 ÷ 1000) = 0.0158; z* = 1.96; margin = 0.0309, about ±3.1 points.[3] The 95% interval is 50.9% to 57.1%.
Critical values by confidence level
Higher confidence means a larger critical value and a wider interval. The t critical value is larger than z for small samples and moves toward it as n grows.[5][6]
| Confidence | z* | t*, n = 10 | t*, n = 30 | t*, n = 100 |
|---|---|---|---|---|
| 80% | 1.282 | 1.383 | 1.311 | 1.29 |
| 90% | 1.645 | 1.833 | 1.699 | 1.66 |
| 95% | 1.96 | 2.262 | 2.045 | 1.984 |
| 98% | 2.326 | 2.821 | 2.462 | 2.365 |
| 99% | 2.576 | 3.25 | 2.756 | 2.626 |
| 99.9% | 3.291 | 4.781 | 3.659 | 3.392 |
t or z: which interval for a mean?
Use the t interval whenever you estimate the spread from the sample itself, which is almost always.[2] The z interval assumes the population standard deviation σ is known in advance, which happens mainly in textbook exercises and in long-running processes with a known spread. For small samples the t interval also assumes the data come from a roughly normal population; check for strong skew or outliers with the statistics calculator.
Proportions: the Wald and Wilson intervals
The textbook interval for a proportion (called the Wald interval) works when there are enough successes and failures; with small counts it can be badly off, and it can even run below 0% or above 100%.[3][4] OpenStax requires more than five successes and five failures; many courses ask for at least ten. The calculator always prints the Wilson score interval as well, which Brown, Cai and DasGupta recommend for small n.[4] For 3 successes in 20 trials, the Wald interval is 0% to 30.6%, the Wilson interval 5.2% to 36%.
What “95% confidence” meansIf you repeated the sampling many times and built an interval each time, about 95% of those intervals would contain the true value. It is a statement about the method, not a 95% chance that this particular interval is right.
Common confidence interval mistakes
- Using z* with a small sample and s. Use t* with n − 1 degrees of freedom.
- Using the SD instead of the standard error. Divide s by √n first.
- Reading overlap as “no difference”. Two intervals can overlap while the difference is still significant; test the difference with the t-test calculator.
- Typing a percent as a proportion. Enter successes and the sample size; the calculator does the division.
Related: the p-value calculator and the z-score calculator.
How we check this calculator
Tests check the critical values against NIST tables (t* = 2.228139 for 10 df, 2.756386 for 29 df at 99%), the worked mean example (t* = 2.063899 for n = 25, margin 4.127797) and the Wilson interval for 8 of 10 (0.4902 to 0.9433).[5]
- 14 November 2026: page and calculator published.
More statistics calculators
- Statistics calculatorMean, median, mode, SD, quartiles and outliers
- Standard deviation calculatorSample and population SD, step by step
- Z-score calculatorz, percentile and area under the normal curve
- P-value calculatorFrom z, t, chi-square or F
- t-test calculatorOne-sample, Welch, pooled and paired
- Binomial distribution calculatorExactly, at most, at least x successes
Frequently asked questions
How do you calculate a 95% confidence interval?
Mean ± t* × (s ÷ √n), with t* from the t distribution at n − 1 degrees of freedom (1.96 for z). For n = 30, mean 74.2 and SD 8.5: 74.2 ± 3.17.
What is the margin of error?
Half the width of the interval: the critical value times the standard error. A poll of 1,000 people has a margin of error of about ±3 percentage points at 95% confidence.
How does sample size change the interval?
The standard error shrinks with √n, so four times the sample gives an interval about half as wide.
When should I use the Wilson interval?
Whenever the number of successes or failures is small, or p̂ is close to 0% or 100%. It stays inside 0–100% and has coverage closer to the stated level.
Can I get a confidence interval from raw data?
Yes. Choose “A mean, from raw data” and paste the numbers; the calculator finds the mean, the sample SD and n, then builds the t interval.
Sources
- 1.3.5.2 Confidence Limits for the Mean
- Introductory Statistics 2e, 8.2 A Single Population Mean using the Student t Distribution
- Introductory Statistics 2e, 8.3 A Population Proportion
- Interval Estimation for a Binomial Proportion (Brown, Cai and DasGupta)
- 1.3.6.7.2 Critical Values of the Student’s t Distribution
- 1.3.6.7.1 Cumulative Distribution Function of the Standard Normal Distribution