How to find sample size for a margin of error

By Jude Wallis · Published

Set the margin of error equal to your target and solve for nn. For a proportion that gives n=(zME)2p(1p)n = \left(\frac{z^*}{ME}\right)^2 p^*(1 - p^*). With no prior estimate use p=0.5p^* = 0.5, the value that makes p(1p)p^*(1 - p^*) largest. Round the answer up unless it is already a whole number.

AP Statistics: Unit 3 (topics 3.3 Constructing a Confidence Interval for a Population Proportion). The Fall 2026 AP Statistics course has no standalone topic on choosing a sample size. It sits inside topic 3.3 on constructing a confidence interval for a population proportion, where the margin of error formula comes from, and the mean version belongs to topic 4.2.

Solve the margin of error formula for n

The margin of error of a confidence interval for a proportion is

ME=zp(1p)nME = z^* \sqrt{\frac{p^*(1 - p^*)}{n}}

where zz^* ("z-star") is the critical value for your confidence level and pp^* ("p-star") is a planning value for the proportion, chosen before any data exist. Square both sides, multiply by nn, divide by ME2ME^2:

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

Everything on the right is a decision you make in advance. How confident do you want to be, which fixes zz^*. How precise do you want to be, which fixes MEME. What are you willing to assume about the proportion, which fixes pp^*. Nothing on the right comes from data, which is the point: this calculation happens before you sample anybody.

The three critical values you need:

Confidence levelzz^*
90%1.645
95%1.960
99%2.576

Write the target margin as a decimal, not a percentage. Three percentage points is ME=0.03ME = 0.03, never 3.

Why 0.5 is the conservative choice for p-star

When you have no prior estimate of the proportion, use p=0.5p^* = 0.5. The reason is that nn is directly proportional to p(1p)p^*(1 - p^*), and that product is as large as it can possibly be at 0.5.

pp^*p(1p)p^*(1 - p^*)
0.100.0900
0.200.1600
0.300.2100
0.400.2400
0.500.2500
0.600.2400
0.700.2100
0.800.1600
0.900.0900

The table peaks in the middle and falls away symmetrically, and one line of algebra says why it must:

p(1p)=0.25(p0.5)2p(1 - p) = 0.25 - (p - 0.5)^2

Multiply out the right side and you get 0.25p2+p0.25=pp20.25 - p^2 + p - 0.25 = p - p^2, which is p(1p)p(1-p). The subtracted term is a square, so it is never negative, so the product can never exceed 0.25 and reaches 0.25 only when p=0.5p = 0.5.

That is what conservative means here. Plan with p=0.5p^* = 0.5 and the sample size you compute is big enough no matter what the true proportion turns out to be. The realized margin is built from the p^\hat{p} your sample gives you, not from the true pp, so if your sample splits exactly 50-50 you hit your target margin exactly and any other p^\hat{p} gives an interval narrower than you asked for. You can overshoot on precision, never undershoot.

Round up, and the check that proves it

A sample size formula almost never returns a whole number. At 95% confidence with ME=0.03ME = 0.03 and p=0.5p^* = 0.5:

n=(1.960.03)2(0.5)(0.5)=(65.3333)2(0.25)=1067.1111n = \left(\frac{1.96}{0.03}\right)^2 (0.5)(0.5) = (65.3333)^2(0.25) = 1067.1111

You cannot survey 0.1111 of a person, and the rule is not "round to the nearest." Round up, to 1068.

Here is the proof, done by putting both candidates back into the margin of error formula:

nnME=1.960.25/nME = 1.96\sqrt{0.25/n}meets the 0.03 target?
10670.030002no, it is above 0.03
10680.029988yes

Rounding down by one single person leaves the margin of error above where you wanted it. Since nn sits under a square root in the denominator, more people always means a smaller margin, so the first whole number at or past 1067.1111 is the smallest sample that works. That is the whole argument, and it is why the rule has no exceptions in the downward direction.

One honest edge case. When the formula lands exactly on a whole number, that whole number is the answer and nothing gets rounded. At ME=0.02ME = 0.02 and p=0.5p^* = 0.5, n=(1.96/0.02)2(0.25)=(98)2(0.25)=2401n = (1.96/0.02)^2(0.25) = (98)^2(0.25) = 2401 exactly, and n=2401n = 2401 gives ME=1.960.25/2401=0.02ME = 1.96\sqrt{0.25/2401} = 0.02 on the nose.

Using a prior estimate to shrink the sample

If a previous study or a pilot survey gives you a credible value for the proportion, use it as pp^* and the required sample falls. Suppose an earlier survey put the proportion near 0.30, and you still want ME=0.03ME = 0.03 at 95% confidence:

n=(1.960.03)2(0.30)(0.70)=4268.4444×0.21=896.3733n = \left(\frac{1.96}{0.03}\right)^2 (0.30)(0.70) = 4268.4444 \times 0.21 = 896.3733

Round up to 897, which is 171 fewer people than the 1068 that p=0.5p^* = 0.5 demands. The check works the same way: n=896n = 896 gives ME=0.030006ME = 0.030006, which misses, and n=897n = 897 gives ME=0.029990ME = 0.029990, which meets the target.

The saving is real but it is a bet. You are assuming the true proportion is near 0.30, and if it turns out to be near 0.50 the interval you finally report will be wider than the one you planned. Use a prior estimate when it comes from a comparable population measured recently. Use 0.5 whenever you are guessing, and 0.5 is what an exam question means when it says you have no prior information.

Sample size for a mean

The same algebra runs on a mean. The margin of error of a zz interval for μ\mu is zσnz^*\frac{\sigma}{\sqrt{n}}, so

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

This version needs a planning value for σ\sigma ("sigma"), the population standard deviation, which usually comes from a pilot study or from past data on the same measurement. There is no equivalent of the p=0.5p^* = 0.5 safe default here, because a standard deviation has no upper bound to be conservative toward.

Notice that the planning formula uses zz^* even though the interval you will eventually build for a mean uses tt^*. That is not sloppiness: tt^* depends on df=n1df = n - 1, and nn is the unknown you are solving for. Planning with zz^* and rounding up is the standard move, and it slightly understates the required nn, so treat a borderline answer as a floor.

With σ=12\sigma = 12 and a target margin of 2 points at 95% confidence, n=(1.96×122)2=(11.76)2=138.2976n = \left(\frac{1.96 \times 12}{2}\right)^2 = (11.76)^2 = 138.2976, so you sample 139. Checking again: n=138n = 138 gives a margin of 2.002155, which misses, and n=139n = 139 gives 1.994940, which meets it.

What a smaller margin costs

Because MEME is squared in the denominator, precision gets expensive fast. Every row below is 95% confidence with p=0.5p^* = 0.5.

Target MEMEnn from the formulasample size
0.1096.0497
0.05384.16385
0.04600.25601
0.031067.111068
0.022401.002401
0.019604.009604

Halving the margin quadruples the sample: 2401 for a margin of 0.02 and 9604 for 0.01, exactly four times as many. That is the same 1/n1/\sqrt{n} relationship that makes confidence intervals so stubbornly wide, seen from the cost side.

Confidence level has a price too. Holding ME=0.03ME = 0.03 and p=0.5p^* = 0.5, you need 752 people at 90% confidence, 1068 at 95%, and 1844 at 99%. Going from 95% to 99% costs 776 extra people to buy four percentage points of confidence. Run your own combinations in the sample size calculator.

Mistakes that give the wrong n

  • Rounding to the nearest whole number. 1067.1111 becomes 1068, not 1067. Rounding down misses the target margin every time, as the check above shows.
  • Putting the margin in as a percentage. ME=3ME = 3 instead of 0.030.03 makes nn ten thousand times too small.
  • Forgetting to square. The critical value over the margin is squared as a unit: (zME)2\left(\frac{z^*}{ME}\right)^2, not (z)2ME\frac{(z^*)^2}{ME}.
  • Using z=1.96z^* = 1.96 for every confidence level. 90% is 1.645 and 99% is 2.576; the whole calculation moves with it.
  • Using a p^\hat{p} from data you have not collected. The planning value comes from prior information or is set to 0.5. If you already had the data you would not be planning the sample.
  • Ignoring the 10% condition. The standard error formula assumes your sample is no more than 10% of the population. If the nn you compute is a large share of a small population, the formula no longer describes the interval you would actually get. Check the conditions for inference before you trust the number, and see what makes a procedure robust for how much each broken condition actually costs.
  • Treating a big planned nn as a substitute for a good sampling method. The formula controls the margin of error, which is sampling variability only. It has no effect on bias, so 10,000 voluntary responses are still worth less than 400 randomly selected ones.

A 95% interval with a margin of error of 3 percentage points

A polling firm wants to estimate the proportion of registered voters who support a ballot measure, with a margin of error of at most 3 percentage points at 95% confidence. No previous polling exists. How many voters must they sample? Verify that one fewer voter would miss the target.

  1. Write the target as a decimal: ME=0.03ME = 0.03. For 95% confidence, z=1.96z^* = 1.96.

  2. No prior information, so use the conservative planning value p=0.5p^* = 0.5, which maximizes p(1p)p^*(1 - p^*) at 0.25.

  3. Substitute into n=(zME)2p(1p)n = \left(\frac{z^*}{ME}\right)^2 p^*(1 - p^*): first 1.960.03=65.3333\frac{1.96}{0.03} = 65.3333.

  4. Square it: (65.3333)2=4268.4444(65.3333)^2 = 4268.4444.

  5. Multiply by p(1p)=0.25p^*(1 - p^*) = 0.25: 4268.4444×0.25=1067.11114268.4444 \times 0.25 = 1067.1111.

  6. Round up, never to the nearest: n=1068n = 1068.

  7. Check the rounded-up value: 0.251068=0.00023408\frac{0.25}{1068} = 0.00023408, whose square root is 0.0152998, so ME=1.96(0.0152998)=0.029988ME = 1.96(0.0152998) = 0.029988, at or below 0.03.

  8. Check the rounded-down value: 0.251067=0.00023430\frac{0.25}{1067} = 0.00023430, whose square root is 0.0153069, so ME=1.96(0.0153069)=0.030002ME = 1.96(0.0153069) = 0.030002, above 0.03. It misses the target.

Sample 1068 voters. The formula returns 1067.1111 and rounding up is required: at n=1068n = 1068 the margin of error is 0.029988, inside the target, while at n=1067n = 1067 it is 0.030002, outside it. One person decides whether the poll meets its own specification.

Sample size for a mean, with the rounding check

A quality engineer wants to estimate the mean fill volume of a bottling line to within 2 millilitres at 95% confidence. Past production runs give a standard deviation of about σ=12\sigma = 12 millilitres. How many bottles should be measured?

  1. Identify the pieces: ME=2ME = 2, σ=12\sigma = 12, and z=1.96z^* = 1.96 for 95% confidence.

  2. Use the mean version of the formula: n=(zσME)2n = \left(\frac{z^* \sigma}{ME}\right)^2.

  3. Compute the inside first: 1.96×122=23.522=11.76\frac{1.96 \times 12}{2} = \frac{23.52}{2} = 11.76.

  4. Square it: (11.76)2=138.2976(11.76)^2 = 138.2976.

  5. Round up: n=139n = 139 bottles.

  6. Check 139: ME=1.96×12139=23.5211.7898=1.994940ME = \frac{1.96 \times 12}{\sqrt{139}} = \frac{23.52}{11.7898} = 1.994940, inside the 2 mL target.

  7. Check 138: ME=1.96×12138=23.5211.7473=2.002155ME = \frac{1.96 \times 12}{\sqrt{138}} = \frac{23.52}{11.7473} = 2.002155, outside it.

  8. Note the caveat: the interval finally reported will use tt^* with df=138df = 138, which is slightly larger than z=1.96z^* = 1.96, so treat 139 as a floor rather than a comfortable answer.

Measure 139 bottles. The formula gives 138.2976 and rounding up is required: 139 bottles give a margin of 1.994940 mL and 138 give 2.002155 mL, just over the limit. Because the planning step uses zz^* while the interval will use tt^*, sampling a few more than 139 is the safer call.

Frequently asked questions

Why do you round the sample size up?

Because nn sits in the denominator under a square root, so a larger sample always gives a smaller margin of error. Rounding down puts you below the sample size the formula demanded, which pushes the margin above your target. At a target of 0.03, n=1067n = 1067 gives 0.030002 and n=1068n = 1068 gives 0.029988. One person is the difference between meeting the specification and missing it.

Why use 0.5 for p-star when you have no estimate?

Because p(1p)=0.25(p0.5)2p^*(1 - p^*) = 0.25 - (p^* - 0.5)^2, which is largest exactly at p=0.5p^* = 0.5, where it equals 0.25. Since nn is proportional to that product, 0.5 gives the largest required sample. Planning with it guarantees your margin of error will be at or below target whatever the true proportion turns out to be.

Do you use z-star or t-star when planning a sample size for a mean?

Use zz^*. The tt critical value depends on df=n1df = n - 1, and nn is exactly what you are solving for, so a tt-based formula would be circular. Planning with zz^* slightly understates the sample needed, so treat the rounded-up answer as a minimum and add a margin if the study is expensive to repeat.

Does this formula guarantee the margin of error I actually report?

It guarantees the planned margin, not the reported one. The interval you finally build uses p^\hat{p} from your data in the standard error, not pp^*, so the realized margin will differ a little. Planning with p=0.5p^* = 0.5 makes that difference land in your favour, since any observed p^\hat{p} away from 0.5 makes the interval narrower than planned.

How does the sample size change if I want a narrower margin?

It grows with the square of the improvement. Halving the margin multiplies the sample by four: at 95% confidence with p=0.5p^* = 0.5, a margin of 0.02 needs 2401 people and a margin of 0.01 needs 9604. Tightening from 0.03 to 0.015 goes from 1068 to 4269.