Eight days of cake sales
A bakery owner counts the cakes sold on eight days: 42, 38, 45, 51, 44, 39, 47, 50. The mean is 44.5 cakes a day. She wants to plan her baking, and 44.5 is the best single guess she has. It is also a guess built on eight days. A different eight days would give a different mean. So the honest answer is not one number. It is a range of plausible values for the true daily average, with a stated level of confidence behind it. That range is a confidence interval, and it works out by hand in a few minutes.
The recipe has three ingredients. The sample mean, which centres the interval. A critical value, which sets how far out the interval reaches. And the standard error, which measures how much sample means bounce around. Put together: sample mean, plus or minus the critical value times the standard error. For the bakery numbers that is 44.5, plus or minus 3.97, an interval from 40.53 to 48.47 cakes a day at 95% confidence. Planning stock for 40 a day would leave her short most days. The interval says so plainly.
The three ingredients, one by one
First the centre. The sample mean of the eight days is 44.5. Add the eight numbers, 356 in total, and divide by 8.
Second the standard error. The sample standard deviation is 4.75: the squared deviations from 44.5 add to 158, dividing by n minus 1 gives 22.57, and the square root is 4.7509. The standard deviation guide on this site works the same eight numbers through the same five steps. The standard error divides that by the square root of n: 4.7509 divided by the square root of 8 is 1.6797. It is the standard deviation of the sample mean itself: how far a fresh sample mean would typically land from the true mean.
Third the critical value. The population standard deviation is unknown here, estimated from the sample, so the t distribution supplies the fence. Eight days means 7 degrees of freedom, and the two-tailed 95% value is t* = 2.3646. Read it off the t table or the critical value calculator on this site.
Margin of error: 2.3646 × 1.6797 = 3.972. Interval: 44.5 − 3.972 = 40.53 to 44.5 + 3.972 = 48.47. The bakery's true average daily demand plausibly sits between 40.53 and 48.47 cakes. The interval is 7.94 cakes wide. A narrower interval would need more days of data, less variable sales, or a lower confidence level. Nothing else narrows it.
t star or z star: the one decision
Two distributions compete for the critical value, and the choice turns on one fact. Is the population standard deviation known? In textbook problems it sometimes is. In real data it almost never is. When sigma is known, use z star: 1.96 for 95% confidence. When sigma is estimated from the sample, use t star, with degrees of freedom n minus 1. The t distribution is wider, which is the price of estimating sigma. With n = 8 that price is real: the correct fence is 2.365, and the z shortcut of 1.96 gives a margin of 3.292 instead of 3.972, an interval about 17% too narrow. The 95% promise quietly breaks.
Large samples close the gap. At 30 degrees of freedom t star is 2.042, only 4% above 1.96, and past 100 the two are barely distinguishable. That is why the rule of thumb says z is fine for large n. It is an approximation all the same. When the sample is small, t star is the honest choice.
A machine fills jars with a known standard deviation of 12 grams. Thirty-six jars average 72 grams. The standard error is 12 divided by the square root of 36, which is 2. The margin at 95% is 1.96 × 2 = 3.92. The interval is 72 − 3.92 = 68.08 to 72 + 3.92 = 75.92 grams. Sigma was known, so z star was the right fence, and no t table was needed.
A second t example: exam marks
Same recipe, different data. Ten exam marks average 71.5, with a sample standard deviation of 3.0277. The standard error is 3.0277 divided by the square root of 10, which is 0.9574. Nine degrees of freedom gives t star 2.2622. The margin is 2.2622 × 0.9574 = 2.166. The 95% confidence interval is 71.5 − 2.166 = 69.33 to 71.5 + 2.166 = 73.67. The class's true average mark plausibly sits in that range. Compare the width with the bakery interval: 4.33 marks against 7.94 cakes. Ten observations and a small standard deviation buy a much tighter interval than eight observations with a large one.
The sample mean calculator runs these same marks and prints the same interval, with the standard error and the t value beside it.
Confidence intervals for a proportion
Means are not the only estimate that gets an interval. A survey of 400 voters finds 240 in favour: p hat is 0.60. The standard error for a proportion is the square root of p hat times (1 minus p hat) over n: the square root of 0.24 divided by 400 is 0.0245. The margin at 95% is 1.96 × 0.0245 = 0.048. The interval is 0.60 − 0.048 = 0.552 to 0.60 + 0.048 = 0.648, or 55.2% to 64.8% support. The conditions check out: 240 in favour and 160 against are both well past 10, so the normal approximation is sound.
At 90% confidence the margin shrinks to 1.645 × 0.0245 = 0.0403, and the interval is 56.0% to 64.0%. Same survey, weaker promise, narrower range. The trade never changes: confidence and width move together.
What 90% and 99% do to the width
Back to the bakery, where the 95% interval ran 40.53 to 48.47. Drop to 90% and t star falls to 1.8946. The margin becomes 3.182 and the interval 41.32 to 47.68, a width of 6.36 cakes. Climb to 99% and t star rises to 3.4995. The margin becomes 5.878 and the interval 38.62 to 50.38, a width of 11.76. The centre never moves. Only the fence moves, and with it the width. A 99% interval is wider because it promises more. There is no free narrowing. More confidence always costs width.
How much data do you need?
The margin formula runs backwards into a sample-size rule. For a mean with a known sigma, n = (z star times sigma divided by E) squared, where E is the margin you will accept. Suppose a survey needs the mean within 2 grams, and sigma is 12. Then n = (1.96 × 12 ÷ 2) squared = 11.76 squared = 138.29, so 139 jars. Always round up: 138 jars would miss the target by a fraction.
Halve the margin you will accept and the sample quadruples. Within 1 gram instead of 2, n = (1.96 × 12 ÷ 1) squared = 23.52 squared = 553.17, so 554 jars. Precision is bought at square-root prices. The same arithmetic in reverse: four times the sample halves the margin. The jars example at n = 36 had a margin of 3.92; at n = 144 the same sigma gives a margin of 1.96. That is the whole bargain of sampling, in one line.
The same interval in a spreadsheet
Excel and Google Sheets both carry the margin as a function. =CONFIDENCE.T(0.05, 4.7509, 8) returns 3.972, the bakery margin. The arguments are alpha, the sample standard deviation, and the sample size. =CONFIDENCE.NORM(0.05, 12, 36) returns 3.92, the jars margin, taking the known population standard deviation instead. Add and subtract the result from the sample mean and the interval is done.
Proportions have no built-in function. Type the formula directly: =1.96*SQRT(0.6*(1-0.6)/400) returns 0.048, the survey margin. Check any of these against one hand calculation first, the bakery 3.972 or the jars 3.92, and then trust the function for the big ones.
Reading the interval honestly
The 95% describes the method, not this one interval. If the same sampling and interval-building were repeated forever, 95% of the intervals produced would contain the true mean. This single interval either contains it or not. The careful wording matters, because the sloppy version treats a fixed unknown as if it were random. The confidence interval explainer on this site works through the same point with the coverage picture.
A second misreading confuses the interval with the data. The bakery interval is 40.53 to 48.47, but the eight days themselves ranged from 38 to 51. The interval is about the mean. The days spread wider than the mean's plausible range, and they should: individual days vary more than averages do. If someone reads the interval as "95% of days sell between 40.53 and 48.47", they have mixed up an interval for a mean with an interval for the data. A prediction interval is the tool for single days, and it is wider.
Third, an interval and a test are the same calculation read two ways. A two-tailed test at alpha 0.05 and a 95% interval agree exactly. The bakery's hypothesised mean of 50 cakes sits outside the interval 40.53 to 48.47, so the test rejects at 0.05. The t statistic confirms it: (44.5 − 50) ÷ 1.6797 = −3.274, p = 0.0136. Whenever the interval excludes the claimed value, the test rejects. Whenever it includes it, the test does not.
Three slips cause nearly every wrong confidence interval. First, using z star on a small sample with an estimated sigma: with n = 8 the correct fence is 2.365, and 1.96 makes the interval about 17% too narrow. Second, reading "95% confident" as a probability about this one interval, or as 95% of the data inside it. Third, forgetting that the interval is about the parameter: a wide interval usually means a small sample or a large standard deviation, and the honest fix is more data. A lower confidence level only weakens the promise.
That is the whole method. Estimate, critical value, standard error. Multiply the last two, add and subtract from the first. Run any of these numbers through the confidence interval calculator and it will agree: the tool shows the same bakery interval, 40.53 to 48.47, with the working beside the answer.
Frequently asked questions
How do I calculate a 95% confidence interval by hand?
Take the sample mean, then add and subtract a margin of error. The margin is a critical value times the standard error. For the bakery's eight days (mean 44.5, s 4.75), the standard error is 1.6797, t star on 7 df is 2.365, the margin is 3.972, and the interval is 40.53 to 48.47 cakes a day.
When do I use z star and when t star?
Use z star when the population standard deviation is genuinely known, or the sample is very large. Use t star whenever sigma is estimated from the sample, which is nearly always in real data. At 30 degrees of freedom t star is 2.042 against z star 1.96, so the gap is small; at 7 df it is 2.365, and the z shortcut makes the interval about 17% too narrow.
How do I calculate a confidence interval for a proportion?
Take p hat, the share in favour, and its standard error, the square root of p hat times (1 minus p hat) over n. For 240 of 400, p hat is 0.60, the standard error is 0.0245, the margin at 95% is 0.048, and the interval is 55.2% to 64.8%. Check that both counts, 240 in favour and 160 against, are past 10.
How do I calculate a confidence interval in Excel?
For a mean with an estimated sigma, =CONFIDENCE.T(0.05, s, n) returns the margin: =CONFIDENCE.T(0.05, 4.7509, 8) is 3.972. For a known sigma, =CONFIDENCE.NORM(0.05, sigma, n) does the same: =CONFIDENCE.NORM(0.05, 12, 36) is 3.92. Proportions have no built-in function, so type =1.96*SQRT(p*(1-p)/n) for the margin. Google Sheets has the same functions.
What does a 95% confidence interval actually mean?
It describes the method, not this one interval. If the same sampling and interval-building were repeated forever, 95% of the intervals produced would contain the true mean. It does not mean 95% of the data falls inside the interval, and it does not mean there is a 95% chance this particular interval contains the mean.