Sample Size Calculator Formula

Understand the math behind the sample size calculator. Each variable explained with a worked example.

Formulas Used

Sample Size (exact)

sample_size_raw = pow(z * sigma / moe, 2)

Standard Error at This n

se_achieved = sigma / sqrt(pow(z * sigma / moe, 2))

Variables

VariableDescriptionDefault
zZ-Value (e.g., 1.96 for 95%)1.96
sigmaPopulation Standard Deviation15
moeDesired Margin of Error3

How It Works

How to Calculate Required Sample Size

Formula

n = (z * sigma / E)^2

where E is the desired margin of error, z is the critical value for the confidence level, and sigma is the population standard deviation. Always round up to the next whole number since you cannot have a fractional observation.

Worked Example

You want a 95% CI with margin of error 3 and estimated SD 15. How many observations are needed?

z = 1.96sigma = 15moe = 3
  1. 01n = (z * sigma / E)^2
  2. 02n = (1.96 * 15 / 3)^2
  3. 03n = (9.8)^2
  4. 04n = 96.04
  5. 05Round up: n = 97 observations needed

Frequently Asked Questions

What if I do not know the population standard deviation?

Use a pilot study estimate, prior research, or the range/4 rule (approximate SD as the data range divided by 4). For proportions, use p = 0.5 for the most conservative estimate.

Why do we always round up?

Rounding down would give a sample slightly too small, resulting in a margin of error slightly larger than desired. Rounding up ensures the margin of error requirement is met or exceeded.

How does doubling precision affect sample size?

Halving the margin of error requires quadrupling the sample size, since n is proportional to 1/E^2. Precision is expensive in terms of sample size.

Learn More

Guide

How to Calculate Confidence Intervals

Step-by-step guide to calculating confidence intervals. Learn when to use z-intervals vs. t-intervals, how to choose a confidence level, and how to interpret the results.

Ready to run the numbers?

Open Sample Size Calculator