This calculator estimates the sample size needed to measure a mean with the precision (margin of error) you set and a given confidence level. It is an estimation approach; if your goal is to test a hypothesis, use the power-based version instead.
Calculator
Calculate the sample size needed to estimate a mean with a target precision.
Explanation
This calculator determines the minimum number of observations needed to estimate a population mean \(\mu\) with a maximum absolute margin of error \(E\) and a given confidence level. It is the analogous calculation to that of a proportion, but for continuous quantitative variables.
The key parameter you must know in advance is the standard deviation \(\sigma\). If you don't have it, you can estimate it from historical data, from the literature, or from a pilot study. A conservative rule of thumb when the distribution is approximately normal: \(\sigma \approx \text{range} / 4\) (a quarter of the likely range of the data).
This formula uses the normal quantile Z, which assumes that \(\sigma\) is known or that the sample is large enough for the t quantile to converge to Z. For small samples (< 30) with unknown \(\sigma\), the real n may be somewhat larger (use the t quantile with n−1 degrees of freedom iteratively).
Sample size formula
\( n = \left(\frac{Z \cdot \sigma}{E}\right)^2 \)
- n: minimum sample size (rounded up to the nearest integer).
- Z: normal quantile — 1.645 (90%), 1.960 (95%), 2.576 (99%).
- \(\sigma\): expected standard deviation of the variable.
- E: maximum tolerable absolute margin of error (in the same units as \(\sigma\)).
Relationship between σ, E and n
The sample size grows quadratically with the required precision: halving E quadruples n. It also grows quadratically with \(\sigma\): if the population's variability doubles, you need four times as many observations for the same precision. Always check that E is reasonable in practical terms: a very small E can make the study unfeasible.
Quick setup
- Standard deviation (σ): take it from previous studies, from the literature, or from a pilot sample of 10–30 observations.
- If you don't have σ: use the rule of range divided by 4 or by 6 as a conservative initial estimate.
- Confidence level: 95% is the standard in most scientific disciplines.
- Maximum error E: define it in practical terms — from what difference relative to the true mean would you make a different decision?
- Expected dropout: divide n by (1 − expected dropout rate).
Worked example
A hospital wants to estimate the mean length of stay (in days) of its post-surgical patients to optimize bed planning. Previous records show that the standard deviation of the length of stay is \(\sigma \approx 4.2\) days. The management team sets that the estimate must be precise within \(E = 0.5\) days with a 95% confidence level (\(Z = 1.960\)).
We apply the formula directly:
\( n = \left(\frac{Z \cdot \sigma}{E}\right)^2 = \left(\frac{1.960 \times 4.2}{0.5}\right)^2 = (16.464)^2 = 271.06 \rightarrow n = 272 \)
At least 272 valid clinical records are needed. However, in hospital studies it is common to have a percentage of incomplete data or exclusions due to medical criteria. If a 15% loss rate is estimated, the number of patients to recruit initially is:
\( n_{\text{recruit}} = \frac{272}{1 - 0.15} = \frac{272}{0.85} \approx 320 \text{ patients} \)
The team will plan data collection over 320 consecutive post-surgical patients, expecting to have at least 272 complete records and thus obtain an estimate of the mean length of stay with a precision of ±0.5 days at 95% confidence.
Sensitivity analysis: if the hospital decided that a precision of ±1 day is sufficient for decision-making, the required sample shrinks drastically: \( n = (1.960 \times 4.2 / 1.0)^2 = (8.232)^2 = 67.77 \rightarrow n = 68 \). This shows that doubling the tolerable margin of error reduces the sample by a factor of 4, making the study much more feasible in resource-constrained settings.
Model assumptions
- Simple random sampling from a very large (or infinite) population.
- The variable follows an approximately normal distribution, or n is large enough for the CLT to guarantee normality of the estimator.
- The standard deviation \(\sigma\) is known or reliably estimated.
- If the population is finite and n/N > 5%, apply the finite population correction.
Common uses
- Estimating mean process or service times.
- Measuring mean consumption or spending among customers or users.
- Statistical process control in manufacturing and quality.
- Surveys on continuous variables (weight, height, score).
How to interpret the result
The value \(n\) returned by the calculator is the minimum number of valid observations you must collect so that the resulting confidence interval has, at most, the specified margin of error \(E\). Always round up (never down), because working with even one fewer observation already makes the real margin exceed the target. If you anticipate that some participant will drop out of the study or that certain observations will be excluded by exclusion criteria, divide \(n\) by \((1 - \text{loss rate})\) to get the recruitment number; for example, with an expected loss of 15%, recruit \(\lceil n / 0.85 \rceil\) subjects.
The sensitivity of \(n\) to the input parameters is asymmetric: \(n\) grows with the square of \(\sigma\) and shrinks with the square of \(E\). This means that if the real standard deviation turns out to be 20% higher than expected, you will need approximately 44% more subjects \((1.2^2 = 1.44)\). For this reason a sensitivity analysis is recommended: calculate \(n\) for \(\sigma - 25\%\), \(\sigma\) and \(\sigma + 25\%\) and use the largest value as a safety margin. Halving \(E\) quadruples \(n\), so if the calculated size turns out to be unfeasible it is preferable to relax the required precision rather than lower the confidence level.
When the resulting \(n\) is very small (for example, < 30), check that the data are reasonably normal or that the central limit theorem can be applied, since the formula is based on the normal distribution. If \(n\) turns out to be unaffordable due to time or cost constraints, consider accepting a larger margin of error or a 90% confidence level instead of 95%. Once the sample has been collected, use the confidence interval calculator for the mean to get the real CI with the observed data.
References and further reading
- Wikipedia: Sample size determination — formulas for means and other variants.
- Wikipedia: Standard deviation — how to estimate σ from prior data.
- Wikipedia (es): Tamaño de la muestra — formulas for mean and proportion.
- Montgomery, D. C. (2019). Introduction to Statistical Quality Control (8th ed.). Wiley. — sample size applications in process control.
Frequently asked questions
- What if I don't know σ? Use a pilot sample of 15–30 observations to estimate it, or look for σ in similar literature. As a conservative fallback, use range/4.
- When should I use t instead of Z? When n < 30 and σ is unknown. In those cases, iterate: calculate n with Z, then replace Z with t(n−1) and recalculate until convergence.
- Is the result exact? It is the theoretical minimum sample. In practice, add a 10–20% buffer to compensate for invalid or lost observations.
- What is the confidence level? The percentage of times the confidence interval computed with that procedure would contain the true population value if we repeated the sampling.