Sample size calculator (target margin of error)
By Jude Wallis · Published
Solve the margin of error formula for n. For a proportion, n = (z*/ME)^2 times p*(1-p*); use the planning value p* = 0.5 when you have no prior estimate, and always round up. For a mean, use n = (z* sigma / ME)^2 with an estimate of the population standard deviation sigma.
required sample size
1068
Steps
- 1.z* for 95% confidence = 1.96
- 2.n = (z*/ME)² x p*(1 - p*) = (1.96/0.03)² x 0.5 x 0.5
- 3.n = 1067.07
- 4.always round UP: n = 1068
AP Statistics: Unit 3 (topics 3.3 Constructing a Confidence Interval for a Population Proportion). In the Fall 2026 AP Statistics course, estimating the minimum sample size from a target margin of error is a learning objective only for proportions (Unit 3, topic 3.3, objective 3.3.D), which directs you to use the planning value p* = 0.5 when no prior estimate is available. The mean version on this page is a college-level extension the AP course does not require; it uses the same margin of error idea as Unit 4, topic 4.2, but that topic asks you to compute the margin of error for a given sample, not to solve for the sample size.
What this sample size calculator does
A sample size calculator answers a planning question you face before collecting any data: how many observations do you need so your confidence interval is no wider than you want? Here is the sample size.
This task almost always means the same thing: choose a target margin of error and a confidence level, then solve for . The margin of error, written , is the half-width of the confidence interval, so a 95% interval reaches above and below your estimate.
The tool works backward from the margin of error formula. You already know the formula that turns a sample size into a margin of error, and the calculator rearranges it to solve for .
The formula for a proportion
For a population proportion, the margin of error is the critical value times the standard error, where the critical value is the multiplier set by your confidence level. Rearranging that formula to solve for the sample size gives:
Here is a planning value for the population proportion, the best guess you have before sampling. If a past study or pilot gives you a value, use it. If you have nothing to go on, use .
The value is the conservative default because is largest when , where it equals . Any other planning value gives a smaller product and a smaller required sample, so produces a safe upper bound on .
Always round up to the next whole number. Rounding down leaves too small, which makes the actual margin of error larger than your target, while rounding up keeps the margin of error at most what you asked for.
The formula for a mean
For a population mean, you need an estimate of the population standard deviation, written (sigma). The sample size formula is:
Get from past data, a pilot sample, or a reasonable range estimate. A larger means more spread, so you need a larger sample to pin the mean down to the same margin of error.
One caveat for AP Statistics: the confidence interval for a mean uses a critical value, and depends on , the number you are trying to find. To avoid that loop, use as an approximation when planning, then round up and treat the result as a planning target rather than an exact requirement.
Critical values for common confidence levels
Your confidence level sets the critical value . Higher confidence uses a larger , which raises the required sample size.
| Confidence level | Critical value |
|---|---|
| 90% | 1.645 |
| 95% | 1.960 |
| 99% | 2.576 |
You can read these off a z-table or use the standard values above.
How to use the calculator
- Choose whether you are estimating a proportion or a mean.
- Enter your target margin of error as a decimal, for example for 3 percentage points.
- Pick a confidence level, which sets .
- For a proportion, enter a planning value or leave it at . For a mean, enter your standard deviation estimate .
- Read off , already rounded up.
The same steps appear in the worked examples below, with every arithmetic step shown. For the full margin of error formula that this reverses, see the margin of error calculator, and for building the interval itself see how to calculate a confidence interval. This planning step belongs to Unit 3 on inference for proportions.
Sample size for a proportion at 95% confidence (ME = 0.03)
You want to estimate the proportion of voters who support a measure with a margin of error of 0.03 (3 percentage points) at 95% confidence. You have no prior estimate, so use the planning value . How many people should you survey?
Pick the critical value. For 95% confidence, .
Use the conservative planning value , so .
Set up the formula: .
Divide inside the parentheses: .
Square that: .
Multiply by 0.25: .
Round up to the next whole number: .
Survey n = 1068 people. Rounding up, rather than to the nearest integer, guarantees the margin of error is at most 0.03.
Sample size for a proportion using a prior estimate
An earlier poll suggested about 20% of customers would upgrade, so . You want a margin of error of 0.04 at 95% confidence. How large a sample do you need?
For 95% confidence, .
Use the prior estimate , so .
Set up the formula: .
Divide inside the parentheses: .
Square that: .
Multiply by 0.16: .
Round up: .
You need n = 385 customers. A credible planning value away from 0.5 lowers the required sample size compared with using .
Sample size for a mean
You want to estimate the mean commute time in a city with a margin of error of 2 minutes at 95% confidence. From past data you estimate the population standard deviation is about 15 minutes. How many commuters should you sample?
For 95% confidence, use as an approximation, because the critical value depends on , which you do not know yet.
Plug into .
Multiply the numerator: .
Divide by the margin of error: .
Square that: .
Round up: .
Sample n = 217 commuters. Because the mean interval uses , treat this as a planning estimate and round up.
Frequently asked questions
Why do you always round up instead of rounding normally?
The formula gives the exact sample size that hits your target margin of error, and it is almost never a whole number. Rounding down would make n too small, so the real margin of error would be larger than your target. Rounding up keeps the margin of error at or below what you asked for.
Why use p* = 0.5 when I have no prior estimate?
The product is largest at , where it equals 0.25. Using 0.5 gives the largest, safest sample size, so you never end up with too few observations no matter what the true proportion turns out to be.
What if I already have an estimate of the proportion?
Use it as . Any planning value farther from 0.5 makes smaller, so you need a smaller sample. Just make sure the estimate is credible, since a bad guess can leave you under-sampled.
Does a higher confidence level need a bigger sample?
Yes. A higher confidence level uses a larger critical value , and grows with the square of . Going from 95% () to 99% () noticeably increases the sample size for the same margin of error.