The two formulas
For a mean, the interval is the sample mean plus and minus a critical value times s over the square root of n. The s over root n part is the standard error: how much a sample mean of this size bounces around from sample to sample. For a proportion it is the observed percentage plus and minus z times the square root of p(1 minus p) over n. Both have the same shape — an estimate, plus and minus a critical value times the standard error of that estimate.
Worked through: 25 measurements averaging 96.35 with a sample standard deviation of 0.42. The standard error is 0.42 divided by 5, which is 0.084. With 24 degrees of freedom the 95 percent t value is 2.064, so the margin is 0.173 and the interval runs 96.18 to 96.52.
Why t below 30 and z above it
If you knew the population standard deviation you would use z and be done. You do not; you have s, estimated from the same small sample as the mean, and that estimate is itself uncertain. The t distribution accounts for the extra uncertainty with fatter tails, which widens the interval. How much wider depends on the degrees of freedom.
| n | df | 95% critical value | Wider than z by |
|---|---|---|---|
| 3 | 2 | 4.303 | 120% |
| 5 | 4 | 2.776 | 42% |
| 10 | 9 | 2.262 | 15% |
| 20 | 19 | 2.093 | 6.8% |
| 30 | 29 | 2.045 | 4.3% |
| large | — | 1.960 | — |
The cutoff at 30 is convention rather than a threshold in the mathematics; t converges smoothly on z, and by 30 the difference is around 4 percent. Using t at every sample size would be marginally more correct and would change nothing you would notice above n of 50.
What 95 percent confidence means, stated carefully
The population mean is a fixed number. You do not know it, but it is not random. The interval you just computed is also fixed, once the data is in. A fixed number is either inside a fixed interval or it is not — there is no probability left to assign. So the statement that the true value is in this interval with probability 0.95 is not merely loose; it attaches randomness to the wrong object.
What the 95 percent describes is the long-run behaviour of the recipe. Draw a fresh sample, run the same procedure, and you get a different interval. Do that indefinitely and 95 percent of those intervals will contain the true value. The confidence belongs to the method, not to any single interval the method produced, in the same way that a test which is right 95 percent of the time is not 95 percent right about the particular result in front of you.
This is not pedantry for its own sake, because the correct version tells you something the loose one hides: one interval in twenty misses entirely, and there is no way to know which. When a later, larger study lands outside an earlier confidence interval, that is a normal outcome at a rate of roughly one in twenty, not proof that someone blundered. It also means an interval computed from a biased sample is not a 95 percent interval at all — the guarantee is conditional on the sampling assumptions holding, and it degrades silently rather than announcing itself.
Narrowing the interval
The width is the critical value times the standard error, so there are exactly three levers.
- Collect more data. The standard error falls with the square root of n, so quartering the width takes sixteen times the observations. This is the only lever that buys real precision.
- Accept less confidence. Dropping from 99 to 95 percent narrows the interval by about 24 percent and raises the miss rate from one in a hundred to one in twenty. That is a trade, not a saving.
- Reduce the underlying variability. Better instruments, tighter procedure, a more homogeneous group. This shrinks s directly and is often cheaper than multiplying the sample, though it can narrow what the result applies to.
What does not work is choosing the confidence level after seeing the interval. If 95 percent leaves the result ambiguous and 90 percent makes it look clean, the ambiguity was the honest finding.
Overlapping intervals are not a test
Two groups with overlapping 95 percent intervals can still differ significantly, and the reverse happens too. The comparison people actually want is an interval on the difference between the groups, which has its own standard error combining both — not a visual check of whether two error bars touch. The overlap heuristic is conservative in the common case, meaning it calls differences inconclusive that a proper test would resolve. For two proportions, the A/B test calculator runs the test on the difference directly, which is the right tool for that comparison.
Before you trust the interval
Every formula here assumes the observations are independent and drawn at random from the population you want to describe. Measurements taken back to back on one machine, responses from whoever volunteered, readings clustered in a single shift — these violate independence and produce intervals that are too narrow, which is the dangerous direction. An interval wrong in that way looks more precise than the data deserves and will not warn you. Check how the data was collected before you check the arithmetic; the second part is easy, and the first is where the errors are.
Questions people ask
Should I enter the standard deviation computed with n or with n minus 1?
Use n minus 1, the sample standard deviation, since you are estimating a population parameter from a sample. It is what the degrees of freedom in the t distribution are built around, and the n version understates the spread and gives an interval that is too narrow. Spreadsheets call it STDEV.S in Excel and STDEV in Google Sheets. With a large sample the two differ by a fraction of a percent, but with the small samples where t matters most the gap is real — at n of 5 the n minus 1 version is about 12 percent larger.
What is the difference between a confidence interval and a margin of error?
They are two ways of writing the same result. The margin of error is the half-width, the plus-or-minus figure; the confidence interval is the estimate with that margin applied to both sides. A poll reported as 45 percent with a margin of ±3.1 points is reporting the interval 41.9 to 48.1 percent. The margin form is more common in survey reporting and the interval form in scientific writing, and the margin of error calculator works the same arithmetic from the survey end.
Can a confidence interval for a proportion go below zero?
The normal approximation used here can produce one, which signals that the approximation has broken down rather than a real result. It happens when the proportion is close to 0 or 100 percent or the sample is small — the formula assumes a symmetric distribution around the estimate, and near a boundary the true sampling distribution is strongly skewed. This page clips the displayed bounds at 0 and 100 and warns when either category has fewer than five observations. In that situation use a Wilson score interval or a Clopper-Pearson exact interval, both of which stay inside the valid range by construction.
How does a prediction interval differ from a confidence interval?
A confidence interval bounds a parameter — where the true mean lies. A prediction interval bounds the next single observation, and it is much wider, because it carries both the uncertainty in the mean and the full spread of individual values around it. From 25 boards averaging 96.35 with s of 0.42, the mean is pinned to within about 0.17, but the next board off the saw could easily land 0.8 away from the mean. Confusing the two produces tolerances that look far tighter than the process can hold, which is a common and expensive mistake.