Sample Size Calculator
Find how large a sample you need to estimate a proportion within a target margin of error. Enter your values below, and see the formula, a worked example, and ready-to-use Python code underneath.
Enter your values
Please enter a margin of error between 0.01% and 50%, and a proportion between 0% and 100%.
What this calculator tells you
Before running a survey, it's useful to know how many responses you actually need. This calculator works backward from your target precision: tell it how confident you want to be and how wide a margin of error you're willing to accept, and it returns the minimum sample size needed to achieve that.
If you're sampling from a known, limited population — rather than an effectively unlimited one — you can also enter a population size to apply a finite population correction, which reduces the required sample size somewhat.
Sample size formula
With finite population correction: n_adj = n / ( 1 + (n − 1)/N )
Python code
You can compute the required sample size manually, or with statsmodels:
# Method 1 — manual calculation import math z = 1.96 # 95% confidence p = 0.5 # expected proportion (conservative default) E = 0.05 # desired margin of error n = (z ** 2 * p * (1 - p)) / (E ** 2) n_rounded = math.ceil(n) print(n_rounded) # 385 # With finite population correction N = 2000 # known population size n_adj = n / (1 + (n - 1) / N) print(math.ceil(n_adj)) # 323 # Method 2 — statsmodels from statsmodels.stats.proportion import samplesize_confint_proportion n2 = samplesize_confint_proportion(proportion=0.5, half_length=0.05)
Worked example
You want to estimate the proportion of customers who prefer a new product, within ±5 percentage points at 95% confidence, with no prior guess about the true proportion.
- 1Use the conservative default proportion.
p = 0.5 (maximizes the required sample size when the true value is unknown) - 2Identify the critical value.
For 95% confidence, z = 1.96 - 3Apply the formula.
n = 1.96² × 0.5 × 0.5 / 0.05² = 0.9604 / 0.0025 = 384.16 - 4Round up to a whole number.
n = 385
You'd need at least 385 respondents. If you're only surveying a limited population of, say, 2,000 people, the finite population correction reduces this to about 323 respondents.
Frequently asked questions
Why is 385 such a commonly cited survey sample size?
385 is the sample size needed to estimate a proportion within ±5% at 95% confidence, assuming the most conservative case of a 50% expected proportion and an effectively infinite population. It shows up constantly because ±5% and 95% are such common defaults for general-purpose surveys.
Why does the calculator default the expected proportion to 50%?
The required sample size is largest when the true proportion is near 50%, so using 50% gives the most conservative (largest) sample size estimate when you don't have a prior guess. If you have good reason to expect the proportion to be far from 50% (e.g., a rare event), using that estimate will reduce the required sample size.
What is finite population correction, and when do I need it?
Finite population correction reduces the required sample size when you're sampling a meaningful fraction of a known, limited population — for example, surveying 400 out of a company's 2,000 employees. It matters most when the sample would otherwise be more than about 5% of the population; for very large or effectively unlimited populations, it makes little difference and can be skipped.
Does a bigger population require a bigger sample?
Not much, once the population is reasonably large. The required sample size for a given margin of error and confidence level levels off quickly as population size grows, which is why national surveys with hundreds of millions of people often need a similar sample size to state-level surveys with a few million.
How much does tightening the margin of error increase the sample size?
Sample size grows with the square of 1 divided by the margin of error, so halving the margin of error (say from ±5% to ±2.5%) roughly quadruples the required sample size.