📘 CodingMarble Learn

Confidence Intervals

A confidence interval is a range of believable values for an unknown population number (a mean μ or a proportion p), worked out from one sample. It has the shape estimate ± margin of error, where margin of error = critical value × standard error. A 95% level means the method catches the true value in about 95% of samples. Higher confidence gives a wider interval; a bigger sample gives a narrower one. If a claimed value lies outside the interval, the data give evidence against the claim.

🎬 Step-by-step story

  1. One sample of 25 children gives a mean height x̄. This one number is a point estimate: our best guess, but almost never exactly right.
  2. We add a margin of error on both sides: x̄ ± z*·σ/√n. The dot becomes a bar. This bar is the confidence interval.
  3. Change the level from 95% to 99%. The critical value grows from 1.96 to 2.576, so the bar gets wider. More trust costs width.
  4. Take a bigger sample, n = 100 instead of 25. The standard error halves, so the bar gets thinner. More data means a sharper answer.
  5. Repeat with 20 new samples. About 19 bars cross the true mean μ (green line); one misses (red). That is what 95% confidence means.
  6. Your turn: change n, the level, σ known or unknown, and a claimed value. Is the claim inside the bar or outside it?

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why not just give the sample mean? Why an interval?

A different sample gives a different x̄. The interval shows how much x̄ could be off, so the reader knows how precise the answer is.

Why is a 99% interval wider and not narrower?

To be more sure of catching μ you need a bigger net. z* grows from 1.96 to 2.576, so the bar stretches.

Why does a bigger sample give a thinner interval?

The SE is σ/√n. More data means x̄ jumps around less from sample to sample, so less wiggle is needed.

Does a 95% interval always contain μ?

No. About 1 in 20 intervals misses. In 3D, the red bar is one that missed even though it was built correctly.

When do I use t instead of z?

When σ is unknown and you use s from the sample. Tick "σ unknown" in free play: for small n the bar becomes wider because t* > z*.

How does an interval check a claim?

Move the purple claim line. Inside the bar: plausible. Outside: the data are evidence against the claim.

Point estimate and interval estimate

We usually cannot measure a whole population, so we take a sample. The sample mean x̄ estimates the population mean μ. The sample proportion p̂ estimates the population proportion p.

A single number like x̄ = 150.4 cm is a point estimate. It is useful, but it does not say how far off it might be.

An interval estimate (confidence interval) gives a range plus a level of trust: "we are 95% confident μ is between 147.3 cm and 153.5 cm".

Every confidence interval has the same shape:

estimate ± (critical value) × (standard error)

The part after ± is called the margin of error (ME). The width of the interval is 2 × ME.

Confidence interval for a mean (z and t)

When σ is known (or n is large)

The standard error of x̄ is σ/√n. The interval is x̄ ± z* · σ/√n.

Levelz*
90%1.645
95%1.96
99%2.576

When σ is unknown: use t

Usually we do not know σ, so we use the sample standard deviation s. This adds extra uncertainty, so we use the t-distribution with n − 1 degrees of freedom: x̄ ± t* · s/√n.

t* is bigger than z* for small samples (for n = 10 at 95%, t* = 2.262 instead of 1.96). As n grows, t* gets closer to z*.

Conditions to check

Confidence interval for a proportion

For a yes/no question, p̂ = (number of yes) ÷ n. Its standard error is √(p̂(1 − p̂)/n).

p̂ ± z* · √(p̂(1 − p̂)/n)

Condition: at least about 10 "yes" and 10 "no" in the sample (n·p̂ ≥ 10 and n(1 − p̂) ≥ 10), so the normal model works.

Choosing the sample size

To get a margin of error E: for a mean, n = (z*σ/E)²; for a proportion, n = p(1 − p)(z*/E)², using p = 0.5 if you have no guess (this gives the safest, largest n). Always round up.

What "95% confident" really means

The true μ is a fixed number. It is the interval that changes from sample to sample. "95% confident" means: if we repeated the sampling many times and built an interval each time, about 95% of those intervals would contain μ (see step 5 in 3D: about 19 of 20 bars cross the green line).

It does not mean "95% of the data lie in the interval", and it does not mean "μ moves around".

What makes an interval narrower?

Comparing two groups and judging claims

Difference of two means

(x̄₁ − x̄₂) ± t* · √(s₁²/n₁ + s₂²/n₂). For large samples t* ≈ z*. For paired data (the same people measured twice), find the difference for each person and build a one-sample interval for the mean difference.

Difference of two proportions

(p̂₁ − p̂₂) ± z* · √(p̂₁(1 − p̂₁)/n₁ + p̂₂(1 − p̂₂)/n₂).

Using an interval to judge a claim

This matches a two-sided hypothesis test: a 95% interval that misses the claimed value goes with rejecting it at the 5% level.

Try it

Ask 20 friends how many hours they slept last night. Find x̄ and s. Build a 95% t-interval with t* = 2.093 (df = 19). Then ask 20 more people and rebuild it with all 40 (t* ≈ 2.023). Is the new interval narrower? In the 3D, move the n slider and watch the bar shrink.

Key formulas and definitions

Worked examples

1. A random sample of 25 children has mean height x̄ = 150.4 cm. The population σ is 8 cm. Find a 95% confidence interval for μ.

SE = 8/√25 = 1.6 cm. ME = 1.96 × 1.6 = 3.14 cm. Interval: 150.4 ± 3.14 = (147.26, 153.54) cm. We are 95% confident the mean height of all such children is between 147.3 cm and 153.5 cm.

2. Repeat Example 1 at 99% confidence.

ME = 2.576 × 1.6 = 4.12 cm. Interval: (146.28, 154.52) cm. It is wider than the 95% interval because we want more confidence.

3. In a survey, 220 of 400 students prefer online notes. Find a 95% interval for the true proportion. Can we say a majority prefer online notes?

p̂ = 220/400 = 0.55. SE = √(0.55 × 0.45/400) = √0.000619 ≈ 0.0249. ME = 1.96 × 0.0249 ≈ 0.049. Interval: (0.501, 0.599). The whole interval is above 0.5, so the data support a majority, but only just.

4. A machine should fill 50 g packets. A sample of 10 packets has x̄ = 48.2 g and s = 2.5 g. Build a 95% interval (t* = 2.262 for df = 9). Is the machine working correctly?

SE = 2.5/√10 ≈ 0.791 g. ME = 2.262 × 0.791 ≈ 1.79 g. Interval: (46.41, 49.99) g. The target 50 g is just outside, so there is evidence the machine is under-filling.

5. How many children must we measure to estimate mean height within ±2 cm at 95% confidence, if σ = 8 cm?

n = (1.96 × 8 / 2)² = (7.84)² = 61.47. Round up: n = 62 children.

6. City A: 50 people, mean daily commute 72 min, s = 10. City B: 60 people, mean 68 min, s = 12. Find a 95% interval for μA − μB (large samples, use 1.96). Is there a real difference?

Difference = 4 min. SE = √(10²/50 + 12²/60) = √(2 + 2.4) = √4.4 ≈ 2.10. ME = 1.96 × 2.10 ≈ 4.11. Interval: (−0.11, 8.11) min. 0 is inside, so we cannot say the commutes really differ.

7. Old app: 90 of 200 users clicked. New app: 120 of 200 clicked. Find a 95% interval for pNew − pOld.

p̂New = 0.60, p̂Old = 0.45, difference = 0.15. SE = √(0.6 × 0.4/200 + 0.45 × 0.55/200) = √(0.0012 + 0.00124) ≈ 0.0494. ME = 1.96 × 0.0494 ≈ 0.097. Interval: (0.053, 0.247). 0 is outside, so the new app really seems better, by about 5 to 25 percentage points.

Common mistakes

Practice quiz

1. A confidence interval has the form:
2. Going from 95% to 99% confidence (same data) makes the interval:
3. Making the sample 4 times bigger changes the margin of error to:
4. For a mean with σ unknown and n = 12, we use:
5. A 95% interval for μA − μB is (2.1, 6.8). This suggests:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a confidence interval in simple words?

A range of believable values for a population number, worked out from a sample, with a stated level of trust such as 95%.

What is the formula for a 95% confidence interval?

For a mean with σ known: x̄ ± 1.96·σ/√n. With σ unknown use x̄ ± t*·s/√n. For a proportion: p̂ ± 1.96·√(p̂(1 − p̂)/n).

How is the margin of error found?

Margin of error = critical value (z* or t*) × standard error. It is half the width of the interval.

Where this is taught

Spain2º BachilleratoStochastic Sense
England (GCSE, A level)Year 12Optional application 2 Statistics (part 1)
England (GCSE, A level)Year 13Optional application 2 Statistics (part 2)
USA (Common Core, NGSS, AP)Grade 12Inference for Categorical Data: Proportions
USA (Common Core, NGSS, AP)Grade 12Inference for Quantitative Data: Means
South Korea고등학교 2학년Analysing data
South Korea고등학교 2학년Statistics
South Korea고등학교 3학년Statistics

Learn first

Learn next

Related lessons

All Maths lessons