Confidence interval calculator

Confidence interval calculator for a mean (t or z), a proportion (Wilson or Wald) or a difference of two means, with the margin of error and both bounds.

Drafted with AI writing toolsUpdated Checked examples: 7

%
Try
Margin of error (±)
Margin of error (±): 2.740646
Maximum decimal places: 6; Nearest, ties away from zero
Lower bound
69.659354
Upper bound
75.140646
Point estimate
72.4
Standard error
1.35
Critical value
2.030108
Degrees of freedom
35

The 95% confidence interval for the mean is 69.6594 to 75.1406 (72.4 ± 2.7406). Confidence describes the repeated-sampling method under its assumptions, not a probability for this particular interval.

95% interval for the mean: 72.4 ± 2.7406

00.10.26870727476μDensity69.659475.1406
How it's calculated S
  1. Standard error

    SE=sn=8.136=1.35SE = \frac{s}{\sqrt n} = \frac{8.1}{\sqrt{36}} = 1.35
  2. Critical value

    t0.975, 35=2.030108t_{0.975,\ 35} = 2.030108
  3. Margin of error

    E=2.030108×1.35=2.740646E = 2.030108 \times 1.35 = 2.740646
  4. Interval

    72.4±2.740646=[69.659354, 75.140646]72.4 \pm 2.740646 = [69.659354,\ 75.140646]

About the confidence interval calculator

For a mean, a confidence interval is a point estimate plus or minus a margin of error: a critical value times the standard error. Proportion intervals can be asymmetric around the sample proportion. For a mean the standard error is s/√n and the critical value comes from Student's t with n − 1 degrees of freedom, or from the normal distribution when σ is known. For a proportion the Wilson score interval is the default, with the Wald formula p̂ ± z√(p̂(1 − p̂)/n) offered for comparison.

Survey results, lab measurements and A/B tests are reported this way. The default sample of 36 with mean 72.4 and standard deviation 8.1 gives SE = 1.35, t = 2.030 on 35 df and a 95% interval of 69.66 to 75.14, or 72.4 ± 2.74.

The confidence level describes the procedure under its sampling and distribution assumptions, not a probability assigned to a fixed parameter in this one interval. Approximate methods such as Wilson or Wald need not achieve exactly the nominal coverage. The first formula is for a mean with unknown σ; the second gives Wilson proportion bounds. Two-sample methods require independent groups, and the pooled method also assumes equal variances.

How to calculate a confidence interval for a mean

A confidence interval for a mean is x̄ ± t × s ÷ √n, with t taken from n − 1 degrees of freedom. For 36 measurements with mean 72.4 and SD 8.1, the standard error is 8.1 ÷ 6 = 1.35 and t = 2.030, so the 95% interval is 72.4 ± 2.74, or 69.66 to 75.14.

Worked step by step:

  1. Standard error: SE = s ÷ √n = 8.1 ÷ √36 = 1.35.
  2. Critical value: a 95% interval leaves 2.5% in each tail, so take t at 0.975 with 35 degrees of freedom: 2.030108.
  3. Margin of error: E = t × SE = 2.030108 × 1.35 = 2.740646.
  4. Interval: 72.4 − 2.740646 = 69.659354 up to 72.4 + 2.740646 = 75.140646.

Changing the confidence level changes only the critical value. At 90% the interval is 70.12 to 74.68, and at 99% it is 68.72 to 76.08.

Margin of error for a poll or proportion

For a proportion p̂ from n responses, the textbook margin of error is E = z × √(p̂(1 − p̂) ÷ n). If 540 of 1,000 people say yes, p̂ = 0.54 and the standard error is √(0.54 × 0.46 ÷ 1,000) = 0.01576.

The 95% margin is 1.96 × 0.01576 = 0.0309, about ±3.1 percentage points. Because n sits under a square root, quadrupling the sample to 4,000 only halves the margin, to ±1.5 points.

Wilson or Wald interval for a proportion

The formula above is the Wald interval. It covers the true proportion less often than stated when n is small or p̂ is near 0 or 1; Brown, Cai and DasGupta (2001) found its coverage can fall far below 95% even with hundreds of observations.

The Wilson score interval stays close to the stated level and never leaves the range 0 to 1 (NIST). For 540 of 1,000 it gives 0.509015 to 0.570679, close to Wald's 0.509110 to 0.570890.

The methods split apart at the extremes. With 0 successes in 20 trials, Wald gives the zero-width interval [0, 0], while Wilson gives 0 to 0.161. Seeing no successes does not show that the true rate is zero.

Wilson bounds are not centered on p̂, so the margin reported with them is half the interval's width, 0.030832 for 540 of 1,000. Quote the two bounds, since p̂ ± that margin misses them slightly.

t or z: is the population SD known?

Use z only when the population σ comes from outside the sample, as with a long-running process. A large sample alone does not make σ known. With σ = 8, the same mean and n = 36, the 95% z interval is 69.79 to 75.01, a margin of 2.613 (NIST).

The t critical value is larger for small samples and shrinks toward z as n grows: 2.262 at n = 10, 2.030 at n = 36 and 1.984 at n = 101, against 1.960 for z.

Confidence interval for a difference in means

For two independent groups, the interval is (x̄₁ − x̄₂) ± t × SE. Welch's method uses SE = √(s₁²/n₁ + s₂²/n₂) with a fractional df, while the pooled method assumes the two populations have equal variances.

Take group 1 with mean 72.4, SD 8.1 and n = 36, and group 2 with mean 68.9, SD 9.4 and n = 40. The difference is 3.5, and the Welch SE is 2.0079 on 73.87 df.

With t = 1.9926, the 95% interval is 3.5 ± 4.0009, from −0.50 to 7.50. Pooled variances give −0.53 to 7.53 on 74 df.

The interval includes 0, so the difference is not significant at the 5% level. A 95% interval excludes 0 exactly when the matching two-sided test, Welch or pooled, rejects at α = 0.05.

The interval estimates mean 1 minus mean 2, so swapping the groups flips the signs. Paired data, such as before-and-after scores for the same people, need an interval for the within-pair differences instead.

What 95% confidence means

The 95% describes the method: across many samples, 95% of intervals built this way contain the true mean. Any one interval, such as 69.66 to 75.14, either contains it or does not.

The interval is not a range for individual values either. With an SD of 8.1, single measurements spread far wider than ±2.74; covering them needs a prediction or tolerance interval.

These intervals assume a random sample of independent observations, and two-sample intervals need independent groups.

The t interval also assumes a roughly normal population. That matters less as n grows, though strong skew or outliers still distort a small sample.

Confidence interval examples

ScenarioLower boundUpper bound
Mean, sample SD, default inputs69.65935475.140646
Mean, known σ = 869.78671575.013285
Proportion 540/1000, Wilson0.5090150.570679
Proportion 0/20, Wilson0.0000000.161125
Default difference of means, Welch-0.5008647.500864

The first two rows use x̄ = 72.4 and n = 36, with s = 8.1 or a known σ = 8, and the last row is the two-group comparison above. All are 95% intervals.

Inputs worth checking

  • Confidence level is two-sided and must be above 0% and below 100%.
  • Raw data gives the sample mean and the sample SD (n − 1). Summary statistics are used exactly as typed, so keep extra digits.
  • Successes is a whole count no larger than n. 540 of 1,000 is 0.54, which is 54%, not 0.54%.

Mistakes that change the interval

  • Using the SD as the standard error. 72.4 ± 1.96 × 8.1 describes individuals, not the mean.
  • Using z with an estimated SD. At n = 10, z = 1.960 instead of t = 2.262 makes the interval 13% too narrow.
  • Reading overlapping intervals as no difference. Two group intervals can overlap while the difference between the means is significant, so build the interval for the difference.

To test a specific value, such as whether the mean differs from 70, use the t-test calculator. To choose n for a target margin of error, use the sample size calculator.

Worked examples

Mean with sample SD, n = 36 (defaults)

Interval for
Mean, σ unknown (t)
Enter
Summary statistics
Sample 1 mean
72.4
Sample standard deviation s₁
8.1
Sample size n₁
36
Confidence level
95%
Critical value
2.030108
Margin of error (±)
2.740646
Lower bound
69.659354
Upper bound
75.140646

Checked against: t₀.₉₇₅,₃₅ = 2.030 (t table); bisection on the A&S 26.7.3 closed form gives 2.0301079283; margin = t·8.1/6

Mean with known σ

Interval for
Mean, σ known (z)
Enter
Summary statistics
Sample 1 mean
72.4
Sample size n₁
36
Known population σ
8
Confidence level
95%
Critical value
1.959964
Margin of error (±)
2.613285

Checked against: z₀.₉₇₅ = 1.959964; margin = z·8/6

Proportion 540/1000, Wilson

Interval for
Proportion
Successes x
540
Sample size n
1000
Method
Wilson score
Confidence level
95%
Lower bound
0.509015
Upper bound
0.570679
Margin of error (±)
0.030832

Checked against: Independent calculation

Proportion 540/1000, Wald

Interval for
Proportion
Successes x
540
Sample size n
1000
Method
Wald (p̂ ± z·SE)
Confidence level
95%
Lower bound
0.50911
Upper bound
0.57089
Margin of error (±)
0.03089

Checked against: Independent calculation

Questions

What does a 95% confidence interval mean?

The method captures the true value in 95% of repeated samples. For the default data the interval is 69.66 to 75.14, but there is not a 95% probability that the true mean lies in that particular range: the true mean is fixed, and this interval either contains it or not. Nor does the interval hold 95% of individual values, which spread far wider (SD 8.1); that needs a prediction or tolerance interval.

How do you calculate the margin of error?

Multiply the critical value by the standard error. For a mean, E = t × s/√n: with s = 8.1 and n = 36, E = 2.030 × 1.35 = 2.74. For a proportion, E ≈ z√(p̂(1 − p̂)/n): 54% of 1,000 respondents gives 1.96 × 0.0158 ≈ 0.031, or ±3.1 percentage points. Because n sits under a square root, quadrupling the sample size halves the margin.

When should I use a z interval instead of a t interval?

Only when the population standard deviation σ is known, which is rare outside textbook problems and long-running process data. With σ estimated from the sample, use t. Its 95% critical value is larger for small samples, 2.262 for n = 10 against 1.960 for z, and approaches z as n grows: 2.030 at n = 36 and 1.984 at n = 101.

Why use the Wilson interval for a proportion?

The Wald interval p̂ ± z·SE covers the true proportion less often than stated when n is small or p̂ is near 0 or 1; Brown, Cai and DasGupta (2001) found its coverage can fall far below 95% even with hundreds of observations. Wilson stays close to the stated level and never leaves the range 0 to 1. With 0 successes in 20 trials Wald gives the zero-width interval [0, 0], while Wilson gives 0 to 0.161.

If a confidence interval for a difference excludes 0, is the result significant?

Yes, for the matching test: a 95% interval for a difference in means excludes 0 exactly when a two-sided test at α = 0.05 using the same method (Welch or pooled) rejects no difference. The default two-group summaries give 3.5 ± 4.0, from −0.5 to 7.5, which includes 0, so the difference is not significant at 5%. The interval also shows how large the effect could plausibly be, which a p-value does not.

About this calculator

xˉ±t1−α/2, n−1sn,p^+z22n±zp^(1−p^)n+z24n21+z2/n\bar x \pm t_{1-\alpha/2,\,n-1}\frac{s}{\sqrt n},\qquad \frac{\hat p + \frac{z^2}{2n} \pm z\sqrt{\frac{\hat p(1-\hat p)}{n} + \frac{z^2}{4n^2}}}{1 + z^2/n}

Sources

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2.1 Confidence limits for the mean
  2. NIST/SEMATECH e-Handbook, §7.2.4.1 Confidence intervals for a proportion (Wilson and normal approximation)
  3. Brown, Cai & DasGupta (2001). Interval estimation for a binomial proportion. Statistical Science 16(2), 101–133

Checked against references

This calculator includes 7 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.

Put this calculator on your site

Paste this where you want the calculator to appear. It is free to use, it stays in step with corrections made here, and the credit line below it links back so your readers can find the full version.

Height
Preview the embed

Keep the credit line. It is the only condition, and it is what keeps these calculators free.