Menu

Confidence Interval Calculator

An interval for a mean or a proportion at 90, 95 or 99%, with the margin of error worked out.

By Nethanel Bar, Co-founder & CEO

Last updated

Want to solve these without the calculator?

The Coddy math course teaches the method itself - you work each step on an interactive board and get told exactly where a move went wrong.

A confidence interval is an estimate with its uncertainty attached

A sample mean is a guess at the population mean, and a guess without a range is a guess you cannot check. The confidence interval is that range: the estimate, plus and minus a margin of error. The margin is a critical value times the standard error, and each of those two factors answers a different question. The standard error is how much the estimate would move from one sample to the next; the critical value is how many of those standard errors the interval reaches to hit the confidence level you asked for.

For a mean the page follows the standard recipe. From raw data it computes the mean and the sample standard deviation exactly, the standard deviation kept as a radical; from a summary it takes your numbers as given. With the standard deviation estimated from the sample, the critical value comes from the t curve with n minus 1 degrees of freedom, which is the honest choice and the default here; the z version is a switch away for a known sigma or a large n. For a proportion the page gives two intervals: the Wald interval, which is the one in most textbooks, and the Wilson score interval, which is the one to report, because Wald misbehaves when the proportion is near 0 or 1 or the sample is small.

The interval is drawn on a number line under the answer, with the estimate marked, because a picture of an interval says something a pair of numbers does not: how wide it is relative to where it sits. An interval for a mean that runs from 4.9 to 5.1 and one that runs from 2 to 8 are both intervals; only one of them is worth reporting to three decimals.

What to know about confidence intervals

  • "95% confident" is a statement about the method, not this interval. Build intervals this way many times and about 95% of them will contain the true value; any single one either does or does not.
  • Wider level, wider interval. A 99% interval reaches about 2.6 standard errors instead of 2, so it is a third wider than a 95% one for the same data.
  • The width shrinks with the square root of n. Four times the data halves the margin of error; a hundred times the data cuts it to a tenth.
  • Use t when sigma is estimated from the sample. With n = 10 the t critical value at 95% is 2.26, not 1.96, and pretending otherwise makes the interval too narrow.
  • For a proportion, report Wilson. The Wald interval can run below 0 or above 1 and is unreliable with fewer than about 10 successes or failures; Wilson stays inside the possible range and keeps its promised coverage.

How to build a confidence interval

  1. Compute the estimate

    The sample mean, or the sample proportion. Keep it exact if you can; the page does.

  2. Compute the standard error

    For a mean, the standard deviation over root n. For a proportion, the root of p(1 − p) over n.

  3. Look up the critical value

    For a mean with estimated sigma, from the t curve with n minus 1 degrees of freedom at your level. For a known sigma or a proportion, from the normal curve: 1.645, 1.960 or 2.576 for 90, 95 or 99%.

  4. Multiply to get the margin, then add and subtract

    Margin of error equals critical value times standard error. The interval is the estimate minus the margin to the estimate plus the margin.

Critical values for a confidence interval

How many standard errors the interval reaches either side of the estimate.

Levelzt, df = 5t, df = 10t, df = 30
90%1.6452.0151.8121.697
95%1.9602.5712.2282.042
99%2.5764.0323.1692.750

Worked examples

A mean from a summary

plain
x̄ = 50, s = 10, n = 25, 95%

The standard error is 10 over 5, which is 2. With 24 degrees of freedom the t critical value at 95% is 2.064, so the margin of error is about 4.13 and the interval runs from 45.87 to 54.13. Using z instead would give 1.96 times 2, a margin of 3.92, slightly too narrow for a sample of 25.

A mean from raw data

plain
2, 4, 4, 4, 5, 5, 7, 9

The mean is exactly 5 and the sample standard deviation is 4√14/7, about 2.138. Dividing by root 8 gives a standard error of about 0.756; with 7 degrees of freedom the t value is 2.365, and the 95% interval is about 3.21 to 6.79.

A proportion

plain
40 successes in 100 trials

The sample proportion is 0.4. The Wald interval is 0.4 plus or minus 1.96 times 0.049, so 0.304 to 0.496. The Wilson interval is 0.309 to 0.498: shifted slightly toward the middle, which is the correction that keeps it honest at the edges. With 40 and 60 both well over 10 the two nearly agree; with 3 successes in 10 they would not.

Confidence interval mistakes

  • Saying there is a 95% chance the true mean is in this interval. The probability statement is about the procedure across repeated samples, not about one fixed interval.
  • Using z with a small sample. Under about n = 30 with sigma estimated from the data, the t critical value is noticeably larger and the z interval is too narrow.
  • Reporting a Wald interval for a rare proportion. With 2 successes in 20 the Wald interval dips below zero; the Wilson interval does not, and is the one to write down.
  • Dividing by n instead of root n for the standard error. The margin would be far too small.
  • Reading a narrow interval as a true one. Width is precision, not accuracy; a biased sample gives a narrow interval around the wrong number.
  • Comparing two overlapping intervals and concluding no difference. Two 95% intervals can overlap while the difference between the means is significant; test the difference directly.

Confidence interval FAQ

How do I calculate a 95% confidence interval?
Take the sample mean, compute the standard error as the standard deviation over the square root of n, multiply by the critical value for 95% (1.96 for z, or the t value for n minus 1 degrees of freedom when the standard deviation is estimated), and add and subtract that margin from the mean. The page does each of those as a separate line.
What does a 95% confidence interval actually mean?
That the method producing it captures the true value 95% of the time across repeated samples. It does not mean there is a 95% probability the true value is in this particular interval; that value is fixed, and the interval either contains it or not. The practical reading is: values inside are consistent with the data, values outside are not.
When do I use t instead of z for a confidence interval?
Use t whenever the standard deviation was estimated from the same sample, which is the usual case. Use z when the population standard deviation is known, or as an approximation when n is large, above a few hundred. With n = 10 the difference is 2.26 against 1.96, which is too much to ignore.
What is the margin of error?
Half the width of the interval: the critical value times the standard error. It is the plus-or-minus that polls quote. A margin of 3% on a 52% result means the interval runs from 49% to 55%.
Why does the page show two intervals for a proportion?
The Wald interval is the textbook formula, p plus or minus z times the root of p(1 − p) over n; it is simple and it is what most courses teach. The Wilson score interval corrects Wald's known failures near 0 and 1 and in small samples, and is what statisticians recommend reporting. Both are shown so you can see the textbook answer and the better one.
How large a sample do I need for a given margin of error?
Rearrange the margin formula: n = (z × σ / E)². For a proportion at the worst case p = 0.5, n = (z / (2E))², so a 3% margin at 95% needs about 1,068 people. Halving the margin quadruples the sample.
Can the confidence interval tell me if a result is significant?
Yes, in one direction: if a 95% interval for a difference excludes zero, the difference is significant at the 5% level, and if an interval for a mean excludes the hypothesised value, the one-sample test rejects it. The interval also tells you how large the effect is, which the test alone does not.

More math tools

Coddy programming languages illustration

Learn math with Coddy

GET STARTED