Probability & Statistics

Confidence Intervals

Visualize how confidence intervals capture the true population mean.

By Riano · Published · Updated · Report a correction

Confidence intervals describe a method

A sample mean changes when we draw another sample. A confidence interval attaches a margin to that estimate. The population mean is fixed; the intervals vary. A 95% procedure captures the mean in approximately 95% of repeated samples under its assumptions. It does not assign a 95% posterior probability to the mean inside one already observed interval.

This experiment draws samples from a normal population with true mean μ = 0 and known standard deviation σ = 1. Each row represents a separate sample mean. Green intervals include zero, including equality at an endpoint; rose intervals miss it. The line at zero reveals which samples succeeded, something usually unknown when analyzing real data.

CI = x ± z1 − α/2 σ / √n; margin = z / √n; full width = 2z / √n

The native confidence choices use rounded z values: 1.645 for 90%, 1.960 for 95%, and 2.576 for 99%. Thus the nominal percentages are approximate normal probabilities. Because the population is normal and σ is known, this formula does not depend on a large-sample approximation to normality.

Predict the width before drawing

Choose 95% and n = 25. The standard error is 1/√25 = 0.2, so the margin is 1.96 × 0.2 = 0.392 and every untruncated interval has full width 0.784. A paper sample mean of 0.20 would give [−0.192, 0.592], which contains zero. That mean is an illustrative calculation, not an input you can set or a promised simulated output.

ConfidencenzMarginFull width
95%251.9600.3920000.784000
95%1001.9600.1960000.392000
99%1002.5760.2576000.515200
  1. Quadruple n from 25 to 100. Its square root doubles, halving the margin and full width.
  2. Keep n = 100 and increase confidence to 99%. The larger z makes the full width 0.515200.
  3. Changing Number of Samples changes how many intervals are drawn, not the theoretical width at fixed n and confidence.

Compare method width with observed coverage

Open the Confidence Intervals interactive experiment. Its three confidence buttons, two sliders, and Draw New Samples button are the complete experiment controls. On a small screen, scroll the controls panel to its statistics and the plot panel to see the entire chart. The legend occupies separate space above the data rows.

  1. Select 95% and set Sample Size (n) to 25. Read Margin ± 0.392000 and Full width 0.784000; inspect green and rose rows.
  2. Set Sample Size (n) to 100. Full width becomes 0.392000. This setting change generates a new batch, so sample centers and captured counts may also change.
  3. Select 99%. At n = 100 the width becomes 0.515200. The new batch need not have more captured intervals than the previous batch, despite the higher nominal confidence.
  4. Select 95% and set Number of Samples to 10. Coverage step becomes 10 percentage points. Captured plus Missed must be 10; exactly 95% observed coverage is impossible with ten intervals.
  5. Press Draw New Samples. Batch advances by one, while the selected settings and theoretical margin stay fixed. Read the new counts without assuming a particular result.
  6. Set Number of Samples to 200. Coverage step becomes 0.5 percentage points. More repetitions reveal coverage in finer increments, but do not guarantee the target percentage.

Know which uncertainty is represented

This is a known-σ normal model with independent draws, not a confidence interval for arbitrary data, proportions, or an unknown standard deviation. If σ is estimated, a different procedure such as a Student t interval may be needed. Increasing n improves precision at the chosen confidence; it does not increase the selected confidence.

  • The simulation uses reproducible mulberry32 uniforms and the Box–Muller normal transform. A changed setting or Draw New Samples advances the internal batch counter. The same action sequence repeats the same samples; the batches are pseudorandom demonstrations, not guarantees about a finite real experiment.
  • Every setting change redraws the samples. Comparing two confidence levels therefore compares method widths on different batches, not nested intervals around the same fixed sample means.
  • The view stays at −1.5 to 1.5. Extreme endpoints are clipped to the plotting window; statistics still use their full mathematical endpoints. For example, 99% at minimum n = 5 has full width about 2.304044, so clipping can be substantial.
  • Coverage is a count divided by Number of Samples. With ten intervals it moves in 10-point increments; with 200 it moves in 0.5-point increments. Rounded displayed margins and rounded z values must not be treated as exact population guarantees.

Primary statistical guidance

The NIST/SEMATECH Engineering Statistics Handbook explains the repeated-sampling interpretation, the normal known-standard-deviation interval, and how its margin scales with sample size. These sources support the statistical model and its assumptions; they do not supply this module’s particular pseudorandom batches or endorse its examples.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Confidence Intervals module.

Try Confidence Intervals on Riano →

More in Probability & Statistics