Sample size

Sample size calculator for a proportion

Calculate the minimum sample size to estimate a proportion with a desired margin of error.

Calculate the minimum sample size to estimate a proportion with the margin of error and confidence level you want. Useful in surveys and prevalence studies.

Calculator

Enter your assumptions and get the recommended minimum sample size for a proportion.

Result pending…

Explanation

This calculator applies Cochran's formula to determine the minimum number of observations needed to estimate a population proportion \(p\) with a preset precision. The goal is for the resulting confidence interval to have a maximum half-width equal to the margin of error \(E\).

The most influential parameter is the expected proportion \(p\): the variance of a proportion is \(p(1-p)\), which reaches its maximum at \(p = 0.5\). That's why, if you have no prior information, using \(p = 0.5\) guarantees the sample will be sufficient whatever the true value is.

This formula assumes simple random sampling from a very large population. If the sample will represent more than 5% of the total, use the calculator with finite population correction.

Sample size formula

\( n = \frac{Z^2 \cdot p \cdot (1-p)}{E^2} \)

  • n: minimum sample size (always rounded up to the nearest integer).
  • Z: normal quantile for the chosen confidence level — 1.645 (90%), 1.960 (95%), 2.576 (99%).
  • p: expected proportion. Use 0.5 if you have no prior information.
  • E: absolute margin of error (half-width of the desired confidence interval).

Interpreting the margin of error

A margin E = 0.05 means your sample estimate \(\hat{p}\) can differ from the true population value by ±5 percentage points, with the probability set by the confidence level. For example, if you get \(\hat{p} = 0.62\) with E = 0.05 at 95%, you can state with 95% confidence that the true proportion is between 57% and 67%. Halving E quadruples the required sample, since n is proportional to 1/E².

Quick setup

  • If you don't know p: use 0.5 — it is the conservative scenario that maximizes the variance and therefore the sample size.
  • If you have pilot data: use the observed proportion; the resulting sample will be smaller if \(p\) is far from 0.5.
  • Confidence level: 95% is the standard in social and health sciences; use 99% for high-impact decisions.
  • Margin of error E: between 0.03 and 0.05 is common in surveys; clinical prevalence studies may need E = 0.01–0.02.
  • Expected dropout: divide n by (1 − expected non-response rate). With 15% dropout: n_recruited = n / 0.85.

Simple example

You want to estimate the percentage of satisfied customers. With p = 0.5, 95% confidence and a maximum error of ±5% (E = 0.05), the result is n ≈ 385. If you reduce the margin to ±3% (E = 0.03), the sample rises to 1,068.

Worked example

An e-commerce store wants to estimate the proportion of visitors who complete a purchase (conversion rate). Data from previous sessions suggest this proportion is approximately \(p = 0.08\) (8%). The analytics team wants an estimate with a margin of error of \(E = 0.02\) (±2 percentage points) and a 95% confidence level (\(Z = 1.960\)).

We apply Cochran's formula with the known values:

\( n = \frac{Z^2 \cdot p \cdot (1-p)}{E^2} = \frac{(1.960)^2 \times 0.08 \times 0.92}{(0.02)^2} = \frac{3.8416 \times 0.0736}{0.0004} = \frac{0.2828}{0.0004} = 707 \)

At least 707 observed visitors are needed. Since not all visitors will have full session tracking (dropouts, tracking failures), a 10% rate of non-response or incomplete data is anticipated. Therefore, the number of sessions to record is:

\( n_{\text{adjusted}} = \frac{707}{1 - 0.10} = \frac{707}{0.90} \approx 786 \text{ sessions} \)

The team will configure the analytics system to collect data on 786 consecutive sessions, expecting to estimate the conversion rate with a precision of ±2 percentage points at 95% confidence.

Conservative scenario (unknown p): if no prior data on the conversion rate were available, common practice is to use \(p = 0.5\), which maximizes the variance \(p(1-p)\) and therefore the required sample size: \( n = (1.960)^2 \times 0.5 \times 0.5 / (0.02)^2 = 3.8416 \times 0.25 / 0.0004 = 2\,401 \). This conservative sample guarantees precision of ±2 pp regardless of the true value of the proportion, at the cost of requiring more than three times as many sessions as the informed estimate.

Model assumptions

  • Simple random sampling (every unit has the same probability of selection).
  • Population very large relative to the sample (n/N < 5%). If this doesn't hold, apply the finite population correction.
  • The normal approximation is valid when n·p ≥ 5 and n·(1−p) ≥ 5.

Common uses

  • Customer satisfaction, opinion and preference surveys.
  • Estimating prevalence or incidence rates in public health.
  • Quality control: percentage of defects or non-conformities.
  • Election polls and voting intention.

How to interpret the result

The calculated \(n\) is the minimum number of valid responses needed so that the confidence interval does not exceed the specified margin of error \(E\). Always round up. Keep in mind that this \(n\) represents complete, usable responses, not simply the number of surveys sent out or individuals contacted. If you expect a non-response or exclusion rate of \(r\,\%\), the number of individuals to contact is \(\lceil n / (1 - r) \rceil\); with a 20% loss, for example, you'll need to contact \(\lceil n / 0.80 \rceil\) people.

The proportion \(p\) is the most influential parameter and, often, the most uncertain. The function \(p(1-p)\) reaches its maximum at \(p = 0.5\), which is also the most conservative scenario: using \(p = 0.5\) when the true proportion is unknown guarantees that \(n\) is never insufficient. If you have a pilot study or prior data pointing to a different value of \(p\), use it to get a more precise \(n\), but perform a sensitivity analysis by varying \(p\) by \(\pm 0.1\) to see how much the result changes; in the central zone (\(p\) between 0.3 and 0.7) the variation in \(n\) tends to be modest, but at the extremes (\(p < 0.1\) or \(p > 0.9\)) a small difference in \(p\) can substantially alter \(n\).

If the resulting \(n\) is unfeasible, the available levers are: (1) increase \(E\) (accept lower precision), (2) reduce the confidence level (e.g., from 95% to 90%), or (3) restrict the target population to make it more homogeneous. Once the data has been collected, use the confidence interval calculator for a proportion to get the real CI; or the hypothesis test calculator if you want to compare \(\hat{p}\) against a reference value.

References and further reading

  • Wikipedia: Sample size determination — full derivation and formula variants.
  • Wikipedia: Margin of error — definition and interpretation in surveys.
  • Wikipedia (es): Tamaño de la muestra — general formulas and statistical context.
  • Cochran, W. G. (1977). Sampling Techniques (3rd ed.). Wiley. — classic reference for the formula.

Frequently asked questions

  • Why does p = 0.5 give the largest sample size? Because the variance p(1−p) is maximized at p = 0.5, making the estimate hardest.
  • What if p is very small (e.g. 0.02)? The sample drops considerably, but the normal approximation may not be adequate. Consider exact Wilson or Clopper-Pearson intervals.
  • When do I apply the finite population correction? When the sampling fraction n/N exceeds 5%. If N = 500 and the estimated n is 50, the correction is relevant.
  • Is the result exact? It is the theoretical minimum sample under the stated assumptions. Real conditions may require adjustments (stratification, clustering, etc.).