MathsStatistics & Probability

Confidence Interval
calculator.

Put a range around a sample mean or proportion, with its margin of error and method.

How it's worked out

A sample mean is a single best guess at the true mean. An interval adds a range that reflects how much samples vary. The confidence level describes the method: in the long run, about 95% of intervals built this way contain the true mean.

When the SD comes from your sample, use the t distribution with n − 1 degrees of freedom. If the population SD σ\sigma is truly known, use z instead.

x‾±t×sn\bar{x} \pm t \times \frac{s}{\sqrt{n}}
x‾±z×σn\bar{x} \pm z \times \frac{\sigma}{\sqrt{n}}

Here x‾\bar{x} is the sample mean, s is the sample SD and n is the sample size. The critical value t or z leaves half of what is left over in each tail. The part after the plus or minus sign is the margin of error.

For a proportion, x successes out of n give an estimate pˆ\hat{p} of xn\frac{x}{n}. The tool defaults to the Wilson method, and it has two parts.

center\displaystyle \text{center}=pˆ+z22n1+z2n\displaystyle {}= \frac{\hat{p} + \frac{z^2}{2n}}{1 + \frac{z^2}{n}}
a\displaystyle a=pˆ(1−pˆ)n+z24n2\displaystyle {}= \frac{\hat{p}(1 - \hat{p})}{n} + \frac{z^2}{4n^2}
half-width\displaystyle \text{half-width}=za1+z2n\displaystyle {}= \frac{z \sqrt{a}}{1 + \frac{z^2}{n}}

It also gives three others. Wald is the plain normal formula. Agresti-Coull adds z22\frac{z^2}{2} successes and as many failures, then applies Wald. Clopper-Pearson works from the binomial distribution itself, with no normal curve.

Critical values by confidence level, z and t with 5 and 10 degrees of freedom
Levelzt, df 5t, df 10
80%1.2821.4761.372
90%1.6452.0151.812
95%1.962.5712.228
98%2.3263.3652.764
99%2.5764.0323.169
99.9%3.2916.8694.587
t with 20, 30 and 60 degrees of freedom
Levelt, df 20t, df 30t, df 60
80%1.3251.311.296
90%1.7251.6971.671
95%2.0862.0422
98%2.5282.4572.39
99%2.8452.752.66
99.9%3.853.6463.46

Worked examples

Ms. Reyes reports a mean test score

Ms. Reyes samples 50 tests, with a mean of 74 and an SD of 12. The standard error is 1.697, and t with 49 degrees of freedom is 2.01.

2.01×1.697\displaystyle 2.01 \times 1.697=3.41\displaystyle {}= 3.41

Her 95% interval runs from 70.59 to 77.41. To bring the margin of error down to 2 points, she needs 141 tests. Four times her sample, 200 tests, brings it to 1.67, a little under half of the current 3.41.

Open this example in the tool

Jo measures ten bolts

Jo measures ten bolts: 12.1, 11.8, 12.4, 12, 11.6, 12.3, 12.2, 11.9, 12.5, 12 mm. They have a mean of 12.08 mm and a sample SD of 0.278 mm. Her 95% interval runs from 11.88 to 12.28 mm.

With so few values, the t interval leans on the lengths being roughly normal. A plot of the values is worth a look before she reports this, because one wild bolt would change both the mean and the SD.

Open this example in the tool

A plant counts 1 fault in 29 units

A quality team finds 1 faulty unit in 29. The Wald formula gives −0.0319 to 0.1009, and a negative share of faults is impossible.

The Wilson interval gives 0.0061 to 0.1718, and Clopper-Pearson gives 0.0009 to 0.1776. Neither is symmetric around the estimate, since little room is left below it.

With 81 of 263, the methods nearly agree: Wilson gives 0.2553 to 0.3662, and Wald gives 0.2522 to 0.3638. Trouble only starts when the counts get small.

Open this example in the tool

Reading your result

Read the width as precision. A narrow interval means the estimate is pinned down well. A wide one says you need more data before you lean on the figure.

Know what moves it. The margin shrinks with the root of the sample, so halving it takes about four times as many. A higher level widens it: for a large sample, 99% is about 31% wider than 95%, the ratio of 2.576 to 1.96.

Use it as a test. A hypothesized value inside the interval cannot be rejected at the matching level. A value outside it can be. That gives you more than a yes or no, as it shows every value still in play.

Need one side only? Swap the critical value so all of what is left over sits in one tail. In practice, the upper limit of a two-sided 90% interval is a one-sided 95% upper bound. For the test scores, that is 76.85.

Check it against a published example. NIST's measurement data has 195 values with a mean of 9.26146 and an SD of 0.022789. The calculation gives 9.258241 to 9.264679, within one step in the last place of the handbook's 9.258242 and 9.264679.

Common mistakes

  • Saying "95% chance the mean is in this interval". The true mean is fixed, and this interval either holds it or does not. The 95% describes how often the method works over many samples.
  • Using z because n is over 30. With an SD from your sample, t is correct at any size. At 36 people, z gives 70.08 to 77.92, and t gives a slightly wider 69.94 to 78.06.
  • Using Wald for small counts. NIST warns that it can give a lower limit below zero. Use Wilson, or the exact method when the sample or the count is very small.
  • Thinking it covers everything that can go wrong. An interval reflects sampling error only. It says nothing about a biased sample or a badly calibrated instrument.
  • Treating overlap as a test. Two intervals can overlap while their difference is still significant. Compare groups with a test built for that.

Questions people ask

Not for one interval you have already worked out. In the frequentist view, the true mean is a fixed number, so that interval either contains it or does not. The 95% is the long-run rate at which the method succeeds. A Bayesian credible interval is what allows a direct probability statement.

Sources