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. 1.z* for 95% confidence = 1.96
  2. 2.n = (z*/ME)² x p*(1 - p*) = (1.96/0.03)² x 0.5 x 0.5
  3. 3.n = 1067.07
  4. 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 nn do you need so your confidence interval is no wider than you want? Here nn 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 nn. The margin of error, written MEME, is the half-width of the confidence interval, so a 95% interval reaches MEME 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 nn.

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 zz^* is the multiplier set by your confidence level. Rearranging that formula to solve for the sample size gives:

n=(zME)2p(1p)n = \left(\frac{z^*}{ME}\right)^2 p^*\left(1 - p^*\right)

Here pp^* 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 p=0.5p^* = 0.5.

The value p=0.5p^* = 0.5 is the conservative default because p(1p)p^*(1 - p^*) is largest when p=0.5p^* = 0.5, where it equals 0.250.25. Any other planning value gives a smaller product and a smaller required sample, so 0.50.5 produces a safe upper bound on nn.

Always round up to the next whole number. Rounding down leaves nn 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 (sigma). The sample size formula is:

n=(zσME)2n = \left(\frac{z^* \sigma}{ME}\right)^2

Get σ\sigma from past data, a pilot sample, or a reasonable range estimate. A larger σ\sigma 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 tt^* critical value, and tt^* depends on nn, the number you are trying to find. To avoid that loop, use zz^* 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 zz^*. Higher confidence uses a larger zz^*, which raises the required sample size.

Confidence levelCritical value zz^*
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

  1. Choose whether you are estimating a proportion or a mean.
  2. Enter your target margin of error MEME as a decimal, for example 0.030.03 for 3 percentage points.
  3. Pick a confidence level, which sets zz^*.
  4. For a proportion, enter a planning value pp^* or leave it at 0.50.5. For a mean, enter your standard deviation estimate σ\sigma.
  5. Read off nn, 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 p=0.5p^* = 0.5. How many people should you survey?

  1. Pick the critical value. For 95% confidence, z=1.96z^* = 1.96.

  2. Use the conservative planning value p=0.5p^* = 0.5, so p(1p)=0.5×0.5=0.25p^*(1 - p^*) = 0.5 \times 0.5 = 0.25.

  3. Set up the formula: n=(zME)2p(1p)=(1.960.03)2×0.25n = \left(\frac{z^*}{ME}\right)^2 p^*(1 - p^*) = \left(\frac{1.96}{0.03}\right)^2 \times 0.25.

  4. Divide inside the parentheses: 1.96/0.03=65.33331.96 / 0.03 = 65.3333.

  5. Square that: 65.33332=4268.444465.3333^2 = 4268.4444.

  6. Multiply by 0.25: 4268.4444×0.25=1067.11114268.4444 \times 0.25 = 1067.1111.

  7. Round up to the next whole number: n=1068n = 1068.

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 p=0.20p^* = 0.20. You want a margin of error of 0.04 at 95% confidence. How large a sample do you need?

  1. For 95% confidence, z=1.96z^* = 1.96.

  2. Use the prior estimate p=0.20p^* = 0.20, so p(1p)=0.20×0.80=0.16p^*(1 - p^*) = 0.20 \times 0.80 = 0.16.

  3. Set up the formula: n=(1.960.04)2×0.16n = \left(\frac{1.96}{0.04}\right)^2 \times 0.16.

  4. Divide inside the parentheses: 1.96/0.04=491.96 / 0.04 = 49.

  5. Square that: 492=240149^2 = 2401.

  6. Multiply by 0.16: 2401×0.16=384.162401 \times 0.16 = 384.16.

  7. Round up: n=385n = 385.

You need n = 385 customers. A credible planning value away from 0.5 lowers the required sample size compared with using p=0.5p^* = 0.5.

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 σ\sigma is about 15 minutes. How many commuters should you sample?

  1. For 95% confidence, use z=1.96z^* = 1.96 as an approximation, because the tt^* critical value depends on nn, which you do not know yet.

  2. Plug into n=(zσME)2=(1.96×152)2n = \left(\frac{z^* \sigma}{ME}\right)^2 = \left(\frac{1.96 \times 15}{2}\right)^2.

  3. Multiply the numerator: 1.96×15=29.41.96 \times 15 = 29.4.

  4. Divide by the margin of error: 29.4/2=14.729.4 / 2 = 14.7.

  5. Square that: 14.72=216.0914.7^2 = 216.09.

  6. Round up: n=217n = 217.

Sample n = 217 commuters. Because the mean interval uses tt^*, 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 p(1p)p^*(1 - p^*) is largest at p=0.5p^* = 0.5, 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 pp^*. Any planning value farther from 0.5 makes p(1p)p^*(1 - p^*) 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 zz^*, and nn grows with the square of zz^*. Going from 95% (z=1.96z^* = 1.96) to 99% (z=2.576z^* = 2.576) noticeably increases the sample size for the same margin of error.