PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabsLessons
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry📊Statistics & Probability
ENRUESPTFRDE

Related simulators

Continue with similar topics in this category — or all 10 in Statistics & Probability.

View category →
NewSchool

p-Value Explained

Launch Simulator

Test statistic on the null density; shaded one- or two-sided tail is the p-value. Why it is not the probability that H₀ is true.

NewFeaturedKids

Central Limit Theorem

Launch Simulator

Pick a parent (uniform, exponential, binomial, die), draw samples of size n = 1, 5, 30; the histogram of means turns normal and its spread shrinks as σ/√n.

NewKids

Law of Large Numbers

Launch Simulator

Coin or die: running mean x̄ₙ for several runs converges to μ; the ±σ/√n envelope shows how slowly.

NewSchool

Type I & II Errors and Statistical Power

Launch Simulator

Two normal curves (H₀ and H₁), a decision threshold; α, β and power 1−β as shaded areas; effect size, σ and n sliders.

NewKids

Normal Distribution & z-Scores

Launch Simulator

Bell curve with μ and σ; shaded tails, the 68–95–99.7 rule, and a built-in z-score converter x → z = (x − μ)/σ.

NewFeaturedKids

Galton Board (Bean Machine)

Launch Simulator

Balls bounce left/right through rows of pegs; the bins fill a binomial that turns into a bell curve. Few rows vs many rows.

PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry
  • Statistics & Probability

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Statistics & Probability/Confidence Interval Simulator

Confidence Interval Simulator

Draw a sample, build a 90/95/99 % interval for μ; repeat 100 times and count how many intervals catch the true mean.

Sampling

20

Confidence level

Method

3 samples/s

Population

50
10

Each sample is n independent draws from the normal population N(μ, σ²). The interval is x̄ ± c·σ/√n with c = z* when σ is treated as known, or x̄ ± c·s/√n with c = t* (ν = n − 1) when σ is estimated by the sample s.d. s. Changing any setting clears the collection so that the coverage count always refers to one fixed procedure. The population is exactly normal; for skewed data the t interval is only approximately valid at small n.

Shortcuts

  • •Space / Enter — draw one sample
  • •P — auto-sampling on / off
  • •R — reset (new random seed)

Measured values

Sample size n20
Confidence level95%
t* (ν = n − 1 = 19)2.0930
Latest x̄—
Latest sample s.d. s—
Latest margin of error—
Latest interval [lo, hi]—
Intervals drawn0
Coverage (contain μ)—
Nominal level95%
Average width—

About this model

The simulator repeats one fixed procedure many times. A population is modelled as a normal distribution N(μ, σ²) with μ = 50 and σ = 10 by default; each press of Draw 1 sample takes n independent values from it, computes the sample mean x̄ = Σxᵢ/n and the sample standard deviation s = √(Σ(xᵢ − x̄)²/(n − 1)), and forms a two-sided interval for μ. With the z method the population σ is treated as known and the interval is x̄ ± z*·σ/√n, where z* = Φ⁻¹(1 − α/2) and α = 1 − level; for 80, 90, 95 and 99 % the critical values are 1.2816, 1.6449, 1.9600 and 2.5758. With the t method σ is replaced by s and the critical value is the quantile t* of Student's t distribution with ν = n − 1 degrees of freedom, so that P(|T| ≤ t*) = level. The inverse normal is computed from Acklam's rational approximation refined by Newton steps against Cody's erfc (full double precision), and the t quantile by inverting the exact t cumulative distribution function F_ν(t) = 1 − ½·I_{ν/(ν+t²)}(ν/2, ½), where I is the regularized incomplete beta function evaluated with the Numerical Recipes continued fraction; the inversion is a safeguarded Newton iteration inside a bisection bracket and agrees with published t tables to better than 10⁻⁶. Each interval is drawn as a horizontal bar centred on its x̄, cyan when it contains μ and pink when it misses, and a counter reports how many of the intervals drawn so far contain μ next to the nominal level. Because the random generator is seeded, Reset starts a fresh reproducible run. The checkbox 'Use z* even though σ is unknown' deliberately makes the textbook mistake of combining the normal critical value with the sample s: for n = 5 at the 95 % level the realised coverage falls to about 88 %, because s underestimates σ more often than not and the z* value ignores that extra uncertainty; switching back to t* restores the nominal coverage at every n. Simplifications: the population is exactly normal, draws are independent and the intervals are symmetric two-sided; for skewed populations or dependent data the stated coverage holds only approximately, and only for large n. Companion simulators: statistics/normal-distribution (the Φ and Φ⁻¹ used here), statistics/central-limit-theorem (why x̄ is approximately normal with s.d. σ/√n), statistics/law-of-large-numbers (how the running coverage settles towards the nominal level), and statistics/p-value and statistics/type-i-ii-errors-power (the same critical values used for hypothesis tests).

Who it's for: Upper secondary and first-year university statistics (AP Statistics, A-level, introductory inference courses).

Key terms

  • confidence interval
  • confidence level
  • coverage probability
  • sample mean x̄ and standard error σ/√n
  • critical value z* and t*
  • Student's t distribution and degrees of freedom
  • margin of error
  • sampling distribution

How it works

Every sample of size n from a normal population N(μ, σ²) gives a sample mean x̄ and a confidence interval x̄ ± c·(scale)/√n; the interval moves from sample to sample while μ stays fixed. The confidence level is a property of the procedure, not of one interval: in the long run about 95 % of the 95 % intervals contain μ, and the simulator counts exactly that as cyan (hit) and pink (miss) bars pile up. When σ is known the critical value z* comes from the inverse normal; when σ is replaced by the sample standard deviation s, the extra uncertainty is paid for by the wider Student t critical value t* with ν = n − 1 degrees of freedom. Tick "Use z* even though σ is unknown" and watch the coverage fall below the nominal level at small n — the under-coverage that the t distribution was invented to fix. The population is exactly normal and the draws are independent; the intervals are two-sided and symmetric.

Key equations

σ known: x̄ ± z*·σ/√n, z* = Φ⁻¹(1 − α/2), α = 1 − level
σ unknown: x̄ ± t*·s/√n, t* = F⁻¹_ν(1 − α/2), ν = n − 1
s² = Σ(xᵢ − x̄)² / (n − 1)
F_ν(t) = 1 − ½·I_{ν/(ν+t²)}(ν/2, ½) (regularized incomplete beta)

Frequently asked questions

Does a 95 % confidence interval mean there is a 95 % probability that μ lies inside the interval I just computed?
No. The population mean μ is a fixed number, and the specific interval on your screen either contains it or does not; nothing random is left once the sample is drawn. The 95 % describes the procedure: if you repeat the sampling many times, about 95 % of the intervals produced will contain μ. The simulator shows exactly this — each bar is one repetition, and the counter approaches 95 % as the number of intervals grows, even though the latest interval may well be one of the pink misses.
Why do the intervals get narrower when n grows, and by how much?
The half-width is c·σ/√n (or c·s/√n), so the width shrinks with the square root of the sample size, not with n itself. Quadrupling n from 20 to 80 halves the width; going from n = 20 to n = 200 shrinks it by a factor of about √10 ≈ 3.2. In the t method a second, smaller effect helps as well: t* with ν = n − 1 decreases towards z* as n grows, from 2.776 at n = 5 to 2.093 at n = 20 and 1.972 at n = 200 for the 95 % level. The coverage, however, does not change with n — a correct 95 % procedure captures μ about 95 % of the time whether n is 2 or 200.
Why does the coverage drop below 95 % when I tick 'Use z* even though σ is unknown'?
The interval x̄ ± 1.96·s/√n pretends that s is the true σ. In a small sample s is itself noisy, and because the distribution of s is skewed it comes out below σ more often than above it. Whenever s is too small, the interval is too short and tends to miss μ; the z* value does not compensate for this. Student's t critical value does: it is larger than z* by exactly the amount needed so that P(|x̄ − μ| ≤ t*·s/√n) equals the nominal level. At n = 5 the gap is large (t* = 2.776 versus 1.960, and the z-with-s coverage is about 88 %); by n = 30 it is small (2.045 versus 1.960, coverage about 94 %), which is where the old rule of thumb 'use z for n ≥ 30' comes from.
Why is the interval in the t method a different width every time, while in the z method all bars have the same length?
In the z method the half-width z*·σ/√n uses only known constants, so every interval has the same length and only its centre x̄ moves. In the t method the half-width t*·s/√n uses the sample standard deviation s, which is recomputed from each new sample; s fluctuates around σ, strongly for small n and weakly for large n, so the bars have different lengths. The average width reported in the panel is therefore slightly different from t*·σ/√n, because the expectation of s is a little less than σ (the factor c₄ is 0.940 at n = 5 and 0.987 at n = 20).