Sample size calculator

How large a sample gives a margin of error of ±E? For a proportion (a poll, a rate) or a mean, with the working.

Choose a proportion or a mean, then set the margin of error you can accept and the confidence level. The curve is the margin of error at each sample size; the dot is the smallest n that meets your target.

How it is calculated

A margin of error is a critical value times a standard error. For a mean the standard error is σ/√n, so the margin is E = z*·σ/√n. Solve that for n and round up[1]:

n = ⌈ (z* · σ ⁄ E)² ⌉    (a mean),    n = ⌈ z*² · p(1 − p) ⁄ E² ⌉    (a proportion)(1)

A proportion is the mean of yes/no answers coded 1 and 0, whose standard deviation is √(p(1 − p)), so the second formula is the first in disguise[2]. The product p(1 − p) is largest at p = 0.5, so a guess of 50 % gives the largest, safest sample size when you have no better idea. established

The square is what makes precision expensive. The margin falls like 1/√n, the same square-root law that narrows the pile of sample means in the simulator, so halving the margin takes four times the sample.

Worked examples

  1. A poll. 95 % confidence, ±3 percentage points, p = 50 %: n = 1.9600² × 0.25 / 0.03² = 1,067.07, so 1,068 people. At ±1.5 points it is 4,269. This is why national polls of about a thousand people are common.
  2. A rarer outcome. If you expect about 10 %, p(1 − p) = 0.09 and ±3 points needs 385.
  3. A mean. Blood-pressure readings with σ about 15 mmHg, wanted within ±3 mmHg at 95 %: (1.9600 × 15 / 3)² = 96.04, so 97 readings.

Assumptions, and what the formula leaves out

  • Simple random sampling from a large population. If you sample a sizeable share of a small population, fewer are needed (the finite population correction, which this calculator does not apply, so its answer errs on the safe side). Cluster samples need more.
  • A planning value. σ or p must be guessed before the data exist, from a pilot study or past work. The achieved margin will differ if the guess was off.
  • The normal critical value z*. When σ will be estimated from the sample, the interval uses Student’s t, which is slightly wider for small samples. In the blood-pressure example the t margin at n = 97 is ±3.02 mmHg rather than ±3; 99 readings bring it under 3. Beyond a few hundred the difference vanishes.
  • Sampling error only. The margin covers the luck of the draw. It says nothing about who refuses to answer, leading questions or measurement error, which no sample size fixes.
  • The answer is the smallest whole n whose margin is at most E; the working shows the unrounded value. Both are exact, however large: they are computed with 80-digit arithmetic from the numbers as you typed them, because a browser’s ordinary arithmetic (about 16 digits) cannot give the answer to the last unit once it passes about 1012. An answer longer than 30 digits is written in scientific notation, to twelve significant figures. Other numbers are shown to at most twelve significant figures.
  • The confidence level can be from 50 % to 99.9999 %. Closer to 100 % a browser’s arithmetic can no longer tell the level from 100 %; below 50 % a margin of error is of little use.

Sources

  1. NIST/SEMATECH (2012). NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2.2 Sample sizes required. National Institute of Standards and Technology. standard
  2. Cochran, W. G. (1977). Sampling Techniques, 3rd edition (ch. 4, the estimation of sample size). John Wiley & Sons, New York. ISBN 978-0-471-16240-7. textbook