← Back to Blog

Confidence Interval Calculator: Margin of Error and Sample Size

Calculate confidence intervals for a population mean or proportion. Find the margin of error, determine required sample size, and interpret what a 95% CI actually means.

Confidence Interval Calculator: Margin of Error and Sample Size

Confidence Intervals

A confidence interval gives a range within which the true population parameter likely falls. A 95% CI means: if you repeated the sampling 100 times, ~95 of those intervals would contain the true value.

CI for Population Mean (large n or known σ)

CI = x̄ ± z*(σ/√n)
z* = 1.645 (90%) | 1.960 (95%) | 2.576 (99%)

Example: n=100, x̄=50, σ=8, 95% CI:
ME = 1.96 × 8/√100 = 1.96 × 0.8 = 1.568
CI = (48.43, 51.57)

CI for Proportion

p̂ ± z* × √(p̂(1-p̂)/n)
Survey: n=400, 230 yes (p̂=0.575), 95% CI:
SE = √(0.575×0.425/400) = 0.02473
ME = 1.96 × 0.02473 = 0.0485
CI = (52.65%, 62.35%)

Required Sample Size

n = (z* × σ/ME)²   (for mean)
n = z*² × p̂(1-p̂)/ME²  (for proportion)

95% CI, ME=±3%, p̂=0.5 (worst case):
n = 1.96² × 0.25/0.03² = 3.84×0.25/0.0009 = 1067

Calculate confidence intervals: Free Confidence Interval Calculator

Confidence Interval Quick-Reference Table

Confidence levelz* (large n)Margin of error formula
90%1.645±1.645 × (σ/√n)
95%1.960±1.960 × (σ/√n)
99%2.576±2.576 × (σ/√n)
99.9%3.291±3.291 × (σ/√n)

How Confidence Intervals Work

A 95% confidence interval (CI) is constructed so that 95% of all such intervals, computed from repeated random samples, would contain the true population parameter. It does NOT mean "95% probability the true value is in this interval" — the true value is either in the interval or not (frequentist view). CI = x̄ ± z* × (σ/√n) for known σ; CI = x̄ ± t* × (s/√n) for estimated σ.

Wider CIs reflect more uncertainty: larger required confidence level, smaller sample size, or greater variability in the data. The margin of error in election polling is typically the half-width of a 95% CI for a proportion: ±1.96√(p̂(1−p̂)/n). With n = 1,000 and p̂ ≈ 0.5, the margin is ±3.1% — the standard "±3 points" reported in polls.

Common Mistakes

  • Misinterpreting the confidence level: "95% CI" means 95% of such intervals contain the true parameter in repeated sampling — not a 95% probability for the single interval you calculated. The Bayesian credible interval correctly gives the 95% probability statement but requires prior beliefs.
  • Confusing CI width with precision: A narrower CI is more precise, but only if the confidence level is the same. A 90% CI is always narrower than a 99% CI from the same data — not more precise, just less confident.
  • Using z* when t* is needed: Use the t-distribution when σ is unknown (almost always). For n > 100, z* and t* are nearly identical, but for n = 10, the difference is substantial: t*(0.025, df=9) = 2.262 vs. z* = 1.960.

Frequently Asked Questions

Q: How do I choose a confidence level?

The choice reflects how wrong you are willing to be. 95% is the scientific standard, balancing informativeness and confidence. Use 99% when false conclusions are costly (medical devices, nuclear safety). Use 90% when speed matters more than precision (early-stage A/B tests, exploratory analysis). The confidence level should be chosen before data collection to avoid p-hacking.

Q: What sample size do I need for a given margin of error?

For a mean: n = (z* × σ / E)², where E is the desired margin of error. For a proportion: n = z*² × p̂(1−p̂) / E². Example: for a 95% CI with ±5% margin on a proportion (p̂ = 0.5): n = 1.96² × 0.25 / 0.05² = 384. This is why many surveys target n ≈ 400 for ±5% precision at 95% confidence.

Q: What is the difference between a CI and a prediction interval?

A confidence interval estimates where the population mean lies. A prediction interval estimates where a single future observation will fall — it is always wider. For a normal distribution, the 95% prediction interval is x̄ ± t* × s√(1 + 1/n), vs. x̄ ± t* × s/√n for the CI. As n → ∞, the CI shrinks to zero width while the prediction interval approaches ±1.96σ.