Confidence Interval Calculator for a Mean

This calculator builds a confidence interval for a population mean from three numbers you already have: the sample mean, the sample standard deviation, and the sample size. It uses the Student t distribution by default, which is the correct choice whenever the standard deviation came from your own data, and switches to the normal (z) distribution when you genuinely know the population value. You get the margin of error, both limits, the critical value, the standard error and the degrees of freedom, plus the same interval at three other confidence levels for comparison.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Sample mean (x̄)The average of your observations, in whatever unit you measured.520
Sample standard deviation (s)The sample standard deviation, computed with n − 1 in the denominator. Not the standard error.50
Sample size (n)How many observations went into the mean. The interval narrows in proportion to the square root of this number.25
Confidence levelThe long-run proportion of intervals built this way that would cover the true mean.95%
Distribution to useChoose t unless the standard deviation is a known population constant rather than a sample estimate.t — σ estimated from the sample

It returns

  • Margin of error (±) — Half the width of the interval: the critical value multiplied by the standard error.
  • Lower confidence limit
  • Upper confidence limit
  • Critical value (t or z)
  • Standard error of the mean
  • Degrees of freedom

The formula

CI=x¯±tα/2,n1sn
SE=sn
CI=x¯±zα/2σn

In plain text: CI = x̄ ± t(α/2, n−1) · s / √n

  • Sample mean
  • sSample standard deviation (divisor n − 1)
  • nSample size (count)
  • tCritical value of Student's t with n − 1 degrees of freedom
  • α1 − confidence level, split equally between the two tails (decimal)

When the population standard deviation σ is genuinely known, replace s with σ and t with the normal critical value z.

Updated Category Confidence Intervals, Margin of Error & Sample Size Verified against published test cases Reading time 10 min

What a confidence interval for a mean actually tells you

A confidence interval is a range of plausible values for a population mean, built from a single sample. You measured 25 parts, or surveyed 400 customers, or ran 12 assays, and you got one number. That number is almost certainly not the population mean. The interval quantifies how far off it could reasonably be.

The precise meaning is about the procedure, not about your one interval. If you repeated the whole exercise many times — draw a fresh sample, compute a fresh mean and standard deviation, build a fresh interval — then 95% of the intervals produced by a 95% procedure would contain the true population mean. Your particular interval either contains it or it does not, and you never find out which. This is why careful writers say “a 95% confidence interval” rather than “there is a 95% probability the mean lies in this range”.

Three things drive the width. Spread widens it: a noisy process gives a bigger s. Sample size narrows it, but only as √n, so quadrupling your sample halves the interval. Confidence widens it: demanding 99% coverage instead of 95% buys certainty with precision. Those three levers are the whole story, and the calculator above shows each of them separately.

The formula, one piece at a time

Start with the standard error, SE = s / √n. This is the standard deviation of the sampling distribution of the mean — how much your sample mean would bounce around if you kept re-sampling. It is not the spread of your data; it is the spread of averages. Because averaging cancels noise, it shrinks with the square root of the sample size. You can compute it on its own with the standard error of the mean calculator, and get s itself from the standard deviation calculator.

Now multiply by a critical value. If you knew the population standard deviation σ, the sample mean would be normally distributed and you would use z — 1.959964 for 95%, which is why polls quote “about two standard errors”. You almost never know σ. You estimate it with s, and that estimate is itself uncertain, so the correct reference distribution is Student's t with n − 1 degrees of freedom. The t distribution has heavier tails than the normal, so its critical values are larger, and the penalty is severe at small n: at df = 1 the 95% multiplier is 12.706 rather than 1.960.

Why n − 1 degrees of freedom? Because you spent one piece of information estimating the mean before you could estimate the spread around it. Once n − 1 of the deviations from x̄ are known, the last one is forced, so only n − 1 of them are free to vary. As n grows, t converges on z: at df = 120 the 95% multiplier is 1.980 against z's 1.960, a gap of one percent. That is why large-sample work often ignores the distinction. You can look up the multiplier on its own with the t critical value calculator.

Worked example: 25 parts with a mean of 520 and s = 50

A supplier ships a component with a nominal tensile strength of 500 MPa. You test 25 units, get a sample mean of 520 MPa and a sample standard deviation of 50 MPa, and you want a 95% confidence interval for the true mean strength of the lot.

  1. Standard error. SE = 50 / √25 = 50 / 5 = 10.000 MPa.
  2. Degrees of freedom. df = 25 − 1 = 24.
  3. Critical value. For 95% confidence, α = 0.05 and each tail holds 0.025. From the t table, t(0.025, 24) = 2.0639.
  4. Margin of error. E = 2.0639 × 10.000 = 20.639 MPa.
  5. Limits. 520 − 20.639 = 499.36 MPa and 520 + 20.639 = 540.64 MPa.

So the 95% interval is 499.4 to 540.6 MPa. Read it against the 500 MPa nominal: the interval contains 500, with 0.64 MPa to spare at the bottom. You therefore have no evidence at the 5% level that the lot mean exceeds nominal, and the equivalent one-sample t-test against μ₀ = 500 gives t = 20/10 = 2.000, which falls short of the same 2.0639 cutoff. That correspondence is exact and always holds: a two-tailed test at α rejects μ₀ precisely when the (1 − α) interval excludes μ₀.

Suppose you want the interval half as wide. Since E is proportional to 1/√n, you need four times the data: 100 parts instead of 25, giving SE = 50/√100 = 5.000 and, with t(0.025, 99) = 1.9842, a margin of error of 9.92 MPa.

How to read the result

Read the interval, not the point estimate. The single most useful habit in applied statistics is to quote “520 MPa, 95% CI 499 to 541” instead of “520 MPa”, because the second version silently claims a precision you do not have.

Check whether a decision-relevant value falls inside. If a specification limit, a contractual minimum, a historical benchmark or a hypothesised value lies inside the interval, your data are compatible with it. If it lies outside, your data are not, at that confidence level. That is the whole inferential content of the interval.

Judge the width against the size of the thing you are measuring. A margin of error of ±20.639 on a mean of 520 is 20.639/520 = 4.0% — fine for a materials survey, hopeless for a calibration laboratory. The calculator flags a margin of error exceeding 20% of the mean, because past that point the estimate rarely supports a decision.

Do not read the interval as covering individual observations. It is an interval for the mean. Roughly 95% of individual parts fall within about x̄ ± 2s, which here is 520 ± 100 — five times wider than the interval for the mean. Confusing the two is the most common misreading of a published interval; if you want a range that covers individual units, you need a prediction interval or a tolerance interval, not this one.

Critical t values by degrees of freedom

Two-tailed critical values of Student's t. Multiply by s/√n to get the margin of error. The bottom row is the normal (z) limit that t approaches as n grows.
df = n − 190%95%99%
16.31412.70663.657
52.0152.5714.032
101.8122.2283.169
151.7532.1312.947
201.7252.0862.845
241.7112.0642.797
301.6972.0422.750
601.6712.0002.660
1201.6581.9802.617
∞ (z)1.6451.9602.576

Values are the standard published two-tailed t table. Read the row for your df and the column for your confidence level.

Mistakes that make a confidence interval wrong

  • Entering the standard error instead of the standard deviation. The field wants s. If you paste an already-divided figure, the calculator divides by √n a second time and the interval comes out far too narrow.
  • Using z because the sample is “large”. The choice depends on whether σ is known, not on sample size. With a sample-estimated s, use t at every n; it converges to z on its own.
  • Applying it to badly skewed data at small n. The t interval relies on the sample mean being approximately normal. With n under about 15 and a strongly skewed or heavy-tailed distribution, actual coverage falls short of the stated level. Plot the data, or use a bootstrap interval instead.
  • Assuming independent observations when they are not. Repeated measures on the same subject, cluster samples and time series all carry correlation that this formula ignores, and ignoring it makes the interval too narrow.
  • Reading the interval as a range for individual values. It bounds the mean; individual observations spread about √n times wider.
  • Sampling a large fraction of a finite population without correcting. If you measured 300 items out of a population of 1,000, this interval is conservative. The margin of error calculator applies the finite population correction.

For a percentage rather than an average — the share of customers who renewed, the fraction of parts out of spec — the sampling distribution is binomial and you want the confidence interval for a proportion, which uses p(1−p) in place of s².

For the gap between two group means, use the confidence interval for a difference of means or read the interval reported by the two-sample t-test calculator. Comparing two separate intervals by eye is a poor substitute: non-overlapping intervals do imply a significant difference, but overlapping ones frequently still differ significantly.

If you are planning a study rather than analysing one, invert the formula. Fix the margin of error you can live with and solve for n; the sample size for a mean estimate calculator and the survey sample size calculator do exactly that.

The t procedure traces to W. S. Gosset, who published it in 1908 under the pen name “Student” while working at the Guinness brewery, precisely because brewing experiments were small-sample problems where the normal approximation failed. That origin is worth remembering: the point of the t distribution is that it stays honest at small n.

Key terms

Margin of error
Half the width of the interval, equal to the critical value times the standard error. Quoted as “±E”.
Standard error
The standard deviation of the sampling distribution of a statistic. For a mean it is s/√n.
Degrees of freedom
The number of independent deviations left after estimating the mean, equal to n − 1 for a one-sample interval.
Coverage
The long-run proportion of intervals built by a procedure that contain the true parameter. A well-behaved 95% procedure has coverage near 0.95.

Frequently asked questions

Should I use t or z for my confidence interval?

Use t unless you know the population standard deviation σ as a fixed constant, which in practice means almost never. The relevant question is not whether your sample is large but whether the spread figure is an estimate. If you calculated it from your own data, it carries uncertainty and t accounts for that. The two answers converge anyway: at df = 120 the 95% t multiplier is 1.980 against z's 1.960.

What does 95% confidence actually mean?

It describes the procedure's long-run success rate, not your specific interval. If you repeated the sampling and interval construction many times, 95% of the resulting intervals would contain the true population mean. Your one interval either does or does not. This is why the correct phrasing is “we are 95% confident” rather than “there is a 95% chance the mean is in here” — the mean is a fixed number, and it is the interval that is random.

Why is a 99% interval wider than a 95% one?

Because covering the truth more often requires casting a wider net. The critical value grows: at df = 24 it goes from 2.064 at 95% to 2.797 at 99%, so the interval widens by a factor of 2.797/2.064 = 1.355, or about 36%. Confidence and precision trade off directly against each other at a fixed sample size; the only way to have both is more data.

How many observations do I need for a given margin of error?

Rearrange the formula: n = (t · s / E)². Because t itself depends on n, solve it iteratively or start with z as a first pass. In the worked example above, halving the margin of error from 20.6 to 10.3 MPa needs roughly four times the sample — 100 parts rather than 25. The sample size for a mean estimate calculator handles the iteration for you.

Can a confidence interval include impossible values?

Yes, and it is a signal that the normal approximation is straining. If you are measuring a quantity that cannot be negative — waiting times, concentrations, counts — and the lower limit comes out below zero, the sampling distribution of your mean is not symmetric enough for the t interval at that sample size. Transform the data, use a bootstrap interval, or collect more observations.

My two groups have overlapping confidence intervals. Are they the same?

Not necessarily. Overlapping intervals are weak evidence at best: two means can differ significantly at the 5% level while their individual 95% intervals overlap by a noticeable amount. The correct comparison builds one interval for the difference between the means, which the two-sample t-test calculator reports. Non-overlap does imply significance, so the eyeball test errs in one direction only.

Does this work for a median or a percentage?

No. This interval is for a mean of roughly normal data. Medians need order-statistic or bootstrap methods, and percentages need the binomial-based proportion interval, where the variance is p(1−p)/n rather than s²/n. Using the mean formula on a 0/1 variable gives a similar answer at moderate p and large n, but it fails badly near 0% or 100%.

What counts as a good margin of error?

There is no universal threshold — it depends on the decision. A useful habit is to express it as a percentage of the mean: the worked example's ±20.639 on 520 is 4.0%. Political polls typically target about 3 percentage points, analytical laboratories often want well under 1% of the mean, and exploratory research routinely tolerates more. Decide what difference would change your action, then size the study so the interval is narrower than that difference.

References