A reviewer runs 25 new phones through the same streaming test until each battery dies. The average is 11.04 hours and the sample standard deviation is 1.20 hours. The reviewer does not publish “11.04 hours” on its own, because a different batch of 25 phones would have given a different average. Instead the report says: mean battery life 11.04 hours, 95% confidence interval 10.55 to 11.53 hours. That pair of numbers is a confidence interval, and every one of them is built the same way:
Here the estimate is the sample mean, the standard error is hours, and the critical value is , so the half-width is hours. The “95%” does not describe this particular interval. It describes the method: if the reviewer repeated the whole experiment on fresh random batches of phones, about 95% of the intervals produced this way would contain the true average battery life of all phones of that model. This article covers how to calculate a confidence interval, what the 95% confidence interval meaning really is, how to choose between z and t, how sample size controls the width, how intervals for proportions work, and the mistakes that come up most often.
What is a confidence interval, and what is the formula?
Start from what you want: the population mean , the average battery life across every phone of this model that will ever be sold. You cannot measure it. You can measure a random sample of phones and compute their mean . The sample mean is an unbiased guess for , but it wobbles from sample to sample, and the size of that wobble is the standard error:
where is the population standard deviation and is its estimate from the sample. The in the denominator is the reason averages become more reliable as samples grow, the quantitative face of the law of large numbers.
The second ingredient is the shape of the wobble. By the central limit theorem, the sample mean is approximately normally distributed around for moderate , whatever the shape of the population. For a normal distribution, 95% of the probability lies within standard deviations of the centre. So
Rearranging the inequality to isolate gives the basic confidence interval formula for a mean with known :
When is unknown, which is almost always, you replace it by and replace by a slightly larger number from the t-distribution:
The quantity is called the margin of error: half the width of the interval.
How do you calculate a confidence interval? A step-by-step example
Here are the 25 battery-life measurements, in hours:
11.6, 12.0, 11.2, 10.3, 10.9, 10.1, 11.7, 13.6, 10.9, 10.7, 12.3, 12.1, 11.8, 10.2, 11.6, 12.6, 9.6, 10.9, 8.7, 9.7, 8.8, 11.2, 9.7, 12.0, 11.8.
Step 1: the sample mean. The values sum to 276.0, so hours.
Step 2: the sample standard deviation. Using the divisor,
Step 3: the standard error. hours.
Step 4: the critical value. With there are degrees of freedom. The value that cuts off 2.5% in each tail of the t-distribution with 24 degrees of freedom is , which rounds to the familiar table value .
Step 5: the margin of error. hours.
Step 6: the interval.
For comparison, if you had (incorrectly) used with the estimated , the margin would be and the interval . At the difference is small, about 5%, but it is not zero, and for small samples it becomes large. The reasons are in the z vs t section below.
What does a 95% confidence interval mean, and how do you interpret it?
This is where most explanations go wrong. The population mean is a fixed number. It does not move. What moves, from sample to sample, is the interval. The 95% is the probability that a future interval, computed from a sample not yet drawn, will land on top of :
The capital letters matter: and are random variables, not yet observed. The probability statement is about the procedure. Figure 1 shows the procedure in action. It draws 20 samples of from a normal population with and , and computes a 95% t-interval from each.
Figure 1 — Twenty 95% t-intervals, each from a fresh random sample of 25 observations from a normal population with μ = 100 and σ = 15 (NumPy default_rng, seed 4). Dots mark the sample means. 19 of 20 cover μ; sample 16 (mean 91.70, interval 84.93 to 98.47) misses. The seed was chosen to show exactly one miss, which is the long-run average for 20 intervals; any single batch of 20 can contain none, one, or several.
Each horizontal bar is one possible report a researcher might have published. The bars have different centres and different lengths, because both and vary. Nineteen of them cross the dashed line; one does not. With a different seed you might see 18, 20 or 17 hits; across many repetitions the long-run fraction settles at 95%. The researcher who happened to draw sample 16 did nothing wrong and has no way of knowing that their interval is one of the misses.
That last point is why the common reading, “there is a 95% probability that lies between 10.55 and 11.53,” is not correct within the frequentist framework that produces the interval. After the data are in, the interval is a fixed pair of numbers and is a fixed number; either is inside or it is not. The honest statement is: this interval was produced by a method that captures the true mean 95% of the time. The confidence is in the method, the way you might trust a thermometer that is accurate 95% of the time without being able to say whether today’s reading is one of the good ones.
If you genuinely want a probability statement about given the data, you need Bayesian inference. A Bayesian credible interval treats as uncertain, combines a prior distribution with the data, and reports a range that contains with 95% posterior probability. With a flat prior and normal data the credible interval for a mean is numerically identical to the t-interval, which is one reason the two get confused. With informative priors, or in small samples of proportions, they can differ noticeably, and they always answer different questions.
In practice, read an interval as the range of parameter values compatible with the data, given the model. Average battery lives between roughly 10.5 and 11.5 hours are consistent with the phone test; an advertised “12 hours” is not. Look at the width as well as the centre: an interval of 8 to 14 would say the experiment was too small to settle anything. And remember the scope: the interval covers only random sampling error, not measurement bias or a non-representative batch.
z vs t interval: which critical value should you use?
The z-interval is exact when the population is normal and is known. That happens in textbook problems and occasionally in industrial settings where a measuring process has a long, stable track record. In almost every real analysis, is estimated by from the same data, and itself is noisy: in some samples it comes out too small, making the interval too narrow at exactly the wrong moment.
William Sealy Gosset worked out the consequence in 1908. For a normal population, the standardized statistic
does not follow a standard normal distribution but a t-distribution with degrees of freedom. Its density is bell-shaped and symmetric like the normal, but with heavier tails, so its 97.5th percentile is larger than 1.96. As grows, becomes a precise estimate of and the t-distribution converges to the normal.
| Degrees of freedom | Sample size n | 95% critical value | Wider than z by |
|---|---|---|---|
| 4 | 5 | 2.776 | 41.7% |
| 9 | 10 | 2.262 | 15.4% |
| 24 | 25 | 2.064 | 5.3% |
| 99 | 100 | 1.984 | 1.2% |
| infinite | very large | 1.960 | 0% |
The rule that follows is simple. Use the t critical value whenever you estimate the standard deviation from the sample, which is nearly always. The often-quoted advice “use z when ” is a holdover from printed tables; at the t value is still 2.042, about 4% larger than 1.96, and software computes the exact value for free.
Does a 95% interval really cover 95% of the time? The claim is testable. A simulation (NumPy default_rng, seed 12345) drew 10,000 samples from a normal population with and and counted how often each kind of 95% interval contained 100.
| Sample size | t-interval coverage | z-interval with s, coverage | Theoretical z coverage |
|---|---|---|---|
| n = 5 | 95.44% | 88.30% | 87.8% |
| n = 25 | 94.90% | 93.74% | 93.8% |
The t-interval delivers what it promises; deviations from exactly 95% are simulation noise of about percentage points. The z-interval with an estimated standard deviation over-promises: at it misses about one time in eight instead of one in twenty. The theoretical column is , the chance that a t variable lands within . This is the cost Gosset identified, measured directly.
How does the confidence level change the width?
A higher confidence level demands a larger critical value, and so a wider interval. For the same 25 phones:
| Confidence level | t critical value (df 24) | Interval (hours) | Width (hours) |
|---|---|---|---|
| 90% | 1.711 | 10.63 to 11.45 | 0.82 |
| 95% | 2.064 | 10.55 to 11.53 | 0.99 |
| 99% | 2.797 | 10.37 to 11.71 | 1.34 |
Going from 95% to 99% makes the interval about 36% wider; a 100% interval would be infinitely wide, true and useless. The confidence level is a choice about how often you are willing to be wrong: a 90% interval misses one time in ten, a 99% interval one time in a hundred. The 95% default is a convention, the same one that made 0.05 the usual significance threshold. Where a miss is expensive, 99% and beyond are common. Whatever level you choose, state it.
How does sample size affect a confidence interval?
The margin of error for a mean is . Because sits under a square root, precision is expensive. Using hours from the phone test:
- with , hours;
- with , hours.
Quadrupling the sample size halves the width. Cutting the width to a tenth needs a hundred times the data.
Turning the formula around gives the standard planning calculation. To achieve margin at the confidence level whose critical value is ,
Suppose the reviewer wants the next test to pin average battery life down to within hours (15 minutes) at 95% confidence. Then
and you always round up, so 89 phones. Two caveats apply. The calculation needs a planning value for , usually from a pilot study or earlier data, and a pessimistic guess is safer than an optimistic one. And since the final analysis will use rather than , the achieved margin will be very slightly larger than planned; at the difference is about 1.4%.
What is a confidence interval for a proportion?
When the data are yes/no outcomes, such as phones that pass or fail a drop test, the estimate is the sample proportion and its standard error is . The textbook confidence interval for a proportion, called the Wald interval, plugs these into the general form:
If 52 of 400 phones fail, and the margin is , giving 9.7% to 16.3%. This is the calculation behind the “plus or minus 3 points” printed under opinion polls; why a sample of about 1000 gives that margin, and why it ignores the larger errors in modern polling, is covered in detail in our article on the margin of error in polls.
The Wald interval behaves badly when is small or is near 0 or 1. Take 3 failures out of 20. The Wald interval is
with an impossible negative lower end. With 0 failures out of 20 it collapses to the single point , claiming certainty from 20 phones. Worse, its actual coverage is far below its nominal level. Computing the exact binomial coverage for : when the true failure rate is 15%, the nominal 95% Wald interval covers it only 81.9% of the time, and when the true rate is 5%, only 63.9% of the time.
The Wilson interval, published by Edwin B. Wilson in 1927, fixes most of this. It inverts the test rather than plugging into the standard error:
For 3 out of 20 it gives 5.2% to 36.0%, an asymmetric interval pulled toward the middle that never leaves ; for 0 out of 20 it gives 0% to 16.1%. Its coverage at is 97.8% when the true rate is 15% and 92.5% when it is 5%, close to the nominal 95% in both cases. For 52 of 400 it gives 10.1% to 16.7%, almost the same as Wald, which is the general pattern: with large samples and proportions away from the edges, the two agree. Wilson is the better default, and many statistical packages now use it or a close relative.
How are confidence intervals related to hypothesis tests?
A 95% confidence interval and a two-sided hypothesis test at the 5% level are two views of the same calculation. The interval contains exactly those values that the test would not reject. If a hypothesized value lies outside the 95% interval, the two-sided p-value for testing it is below 0.05, and vice versa.
The phone data show this precisely. The interval is .
- Testing (inside): , two-sided , not rejected.
- Testing (just outside): , , rejected.
- Testing the advertised : , , firmly rejected.
This is why many statisticians prefer intervals: one interval summarises every such test at once and shows the size of the effect, which a bare p-value hides.
What are the most common confidence interval mistakes?
Reading overlap as “no significant difference.” Suppose two phone models are each tested on 25 units, both with hours. Model A averages 11.0 hours, interval 10.38 to 11.62; model B averages 11.9 hours, interval 11.28 to 12.52. The intervals overlap between 11.28 and 11.62, and it is tempting to conclude the models are indistinguishable. But the standard error of the difference is not the sum of the two standard errors; it is
so with 48 degrees of freedom, . The 95% interval for the difference, to hours, excludes zero. Non-overlapping 95% intervals do imply a significant difference, but overlapping ones do not imply its absence. If you care about a difference, compute the interval for the difference.
Confusing a confidence interval with a range for individual values. The interval is about the average battery life. Individual phones vary far more: in the sample they ranged from 8.7 to 13.6 hours. The range expected to contain a single new phone’s battery life 95% of the time is a prediction interval,
That is about five times wider than the confidence interval, and unlike the confidence interval it does not shrink to zero as grows; it shrinks toward .
Ignoring the assumptions. The t-interval assumes observations are independent, drawn at random from the population of interest, and that the sample mean is close to normal, which holds for normal data at any and for moderately skewed data once is a few dozen. Twenty-five readings from the same phone are not 25 independent phones; a batch from one factory line is not a random sample of all production. For heavily skewed data, or statistics without a simple standard-error formula such as a median or a correlation coefficient, the usual tool is the bootstrap: resample the data with replacement thousands of times, recompute the statistic each time, and take the 2.5th and 97.5th percentiles as the interval. It still assumes the sample is representative and can struggle with very small . If you want a guarantee that holds for any distribution with known , Chebyshev’s inequality gives one, at a price: you need standard errors instead of 1.96 to guarantee at least 95% coverage.
Where did confidence intervals come from?
The t-distribution came first. William Sealy Gosset was a brewer and chemist at Guinness in Dublin, working with small experimental samples where large-sample approximations were unreliable. Guinness did not allow employees to publish work done for the firm under their own names, so his 1908 paper “The Probable Error of a Mean” appeared in Biometrika under the pseudonym “Student.” His statistic was later rescaled by R. A. Fisher into the form now called , and the distribution is still known as Student’s t.
Edwin B. Wilson’s 1927 note “Probable Inference, the Law of Succession, and Statistical Inference” in the Journal of the American Statistical Association contained the interval for a proportion that bears his name, by inverting the normal approximation rather than plugging in the estimate.
The general theory belongs to Jerzy Neyman. Beginning in 1930 R. A. Fisher published his fiducial intervals, probability intervals for a parameter obtained without a prior distribution, an idea Fisher defended for the rest of his life but which never found a fully consistent foundation. Neyman, who said he had been using similar constructions in his work in Poland since about 1930, introduced confidence intervals in English in his 1934 paper on stratified sampling and purposive selection in the Journal of the Royal Statistical Society, and set out the full theory in “Outline of a Theory of Statistical Estimation Based on the Classical Theory of Probability,” published in the Philosophical Transactions of the Royal Society in 1937. He deliberately avoided the word “probability” in the name, calling the guarantee “confidence,” precisely to separate a property of the procedure from a probability about the parameter. At the 1934 discussion meeting, Arthur Bowley reportedly wondered aloud whether the confidence idea was “a confidence trick.” The distinction Neyman insisted on is the one Figure 1 illustrates, and the one that still causes most of the confusion.
The short version
A confidence interval is an estimate plus or minus a critical value times a standard error. For a mean, use ; for a proportion, prefer the Wilson interval over the textbook Wald formula, especially with small samples or rare events. The confidence level is a property of the method, the long-run fraction of intervals that capture the truth, not a probability about the one interval you computed. Width grows with the confidence level and shrinks with , so precision costs data quadratically. And the interval covers only random sampling error under the stated assumptions; bias, dependence and a non-representative sample sit outside it, and no amount of arithmetic will put them back in.
Related topics: How Can a Poll of 1000 People Represent the Whole Country?, What P-Values Really Mean (and What They Don’t), What Is Standard Deviation?, The Central Limit Theorem, What Is a Normal Distribution?, The Law of Large Numbers, Bayesian Inference, Chebyshev’s Inequality, Correlation Coefficient
Frequently asked
What is a confidence interval in simple terms?
It is an estimate with a built-in error bar. Instead of reporting only a sample average, you report the average plus or minus an allowance for sampling noise, for example 11.04 plus or minus 0.49 hours. The allowance is chosen so that the method behind it captures the true population value a stated fraction of the time, usually 95%, when it is applied to many random samples.
How do you calculate a 95 percent confidence interval?
For a mean, compute the sample mean, the sample standard deviation s, and the standard error s divided by the square root of n. Multiply the standard error by the critical value, which is 1.96 when the population standard deviation is known or the sample is very large, and the t-value with n minus 1 degrees of freedom otherwise (2.064 for n = 25). The interval is the mean minus that product to the mean plus that product.
What does a 95 percent confidence interval mean?
It means the procedure that produced the interval captures the true value in 95% of repeated random samples. It does not mean there is a 95% probability that the true value lies inside the particular interval you computed. Once the data are in, the fixed true value is either inside or outside; the 95% describes the long-run reliability of the method.
What is the difference between a confidence interval and a margin of error?
The margin of error is half the width of the confidence interval. A poll reporting 47% with a margin of error of 3 points is reporting the 95% confidence interval from 44% to 50%. The interval is the full range, the margin is the plus-or-minus part, and both refer only to random sampling error.
Why use a t distribution instead of z?
Because in practice the population standard deviation is unknown and has to be estimated from the same sample, which adds extra uncertainty. The t distribution has heavier tails to account for this, so its critical values are larger: 2.776 for 5 observations versus 1.96 for z. Using 1.96 with an estimated standard deviation at n = 5 gives intervals that cover the truth only about 88% of the time instead of 95%.
How does sample size affect a confidence interval?
The width shrinks in proportion to one over the square root of n. Quadrupling the sample size halves the width, and cutting the width by a factor of ten needs one hundred times as many observations. To reach a target margin E at 95% confidence with standard deviation sigma, you need roughly n = (1.96 sigma / E) squared observations.