Tabellab

How Many to Measure? Margin of Error & Sample Size

Lesson 1 of 20Lab

All lessons
  1. How Many to Measure? Margin of Error & Sample SizeLabFree
  2. Sample Size for a Proportion & the Finite Population CorrectionLab Locked
  3. Effect Size: Pooled SD, Cohen's d & the Minimum Detectable EffectLab Locked
  4. Sample Size for Comparing Two Means (NORM.S.INV)Lab Locked
  5. Sample Size for Two Proportions: Sizing an A/B TestLab Locked
  6. The Power Curve: Power vs Sample Size (Scatter Chart)Lab Locked
  7. Power and Minimum Detectable Effect for a Fixed Sample SizeLab Locked
  8. Practical Adjustments: Bonferroni, Unequal Allocation, Dropout & Non-ResponseLab Locked
  9. Paired Designs: Before-and-After Samples & the Correlation BonusLab Locked
  10. Small Samples: Exact Binomial Power vs the Normal ApproximationLab Locked
  11. Cluster Samples: Design Effect, ICC & the Cheapest Cluster SizeLab Locked
  12. Stratified Samples: Proportional vs Neyman AllocationLab Locked
  13. Sample Size for a Correlation: Fisher's z & Confidence LimitsLab Locked
  14. Sensitivity Grid: When the Planning Assumptions Are WrongLab Locked
  15. How Long Must an A/B Test Run? Traffic, Variants & Full WeeksLab Locked
  16. Project: A Complete Study Plan DashboardLab Locked
  17. Count Data: Comparing Two Event Rates & the Exposure You NeedLab Locked
  18. Using a Baseline Covariate: How Much Last Quarter's Data Saves (ANCOVA vs Change Scores)Lab Locked
  19. Fixed Budget, Unequal Costs: the Cost-Optimal Split Between Groups (Chart)Lab Locked
  20. Final Project: A Quarter of A/B Tests – Sizes, Run Times & What FitsLab Locked

You are not signed in — the lab works, but your progress is not saved. Sign up

Lesson 1 of 20 is free. Unlock all 20 hands-on labs, the final exam and your certificate.

Buy course — $9.90
Loading the spreadsheet…

"Give or take?" is the most expensive question in research

A supermarket asks Larkspur Analytics, a small fictional research firm, a simple question: how long do our customers wait at the checkout, give or take? The client wants a number for a board meeting, and it wants that number to be trustworthy. Larkspur could station staff with stopwatches at every till for a month, but every timed customer costs money, in this example USD 4 each. Time too few and the answer is vague. Time too many and the budget is gone before the analysis starts.

Every survey, experiment, quality check and customer study runs into this trade-off, and the answer is a calculation, not a gut feeling. This free first lesson is for analysts, market researchers, students writing a thesis, quality managers, product people and anyone who has been asked "how many do we need?" and did not want to guess. You will measure how precise a small pilot is, turn a precision target into a sample size, and pick the most precise study the budget can pay for, all with standard Excel functions.

The numbers come from the lab above: 24 pilot wait times in minutes. Larkspur Analytics and its supermarket client are fictional, and all wait times and prices are synthetic and used only for teaching.

The core concept: margin of error

"Give or take" has a precise name: the margin of error (MOE). It is the half-width of a confidence interval around the sample mean. If the mean wait is 5.38 minutes with a margin of ±1.43, the 95% confidence interval runs from 3.95 to 6.81 minutes. Loosely speaking, it is the range of true average waits that are consistent with what the sample shows. The margin depends on three things only: how much individual customers differ (the standard deviation s), how sure you want to be (the confidence level, through z), and how many customers you timed (n).

For a mean, the formula is MOE = z × s ÷ √n. For 95% confidence, z is 1.96, which Excel gives you with =NORM.S.INV(0.975). The 0.975 comes from splitting the 5% that is left over into two tails of 2.5% each. The standard deviation s is estimated from the sample with STDEV.S. And n sits under a square root, which is the single most important fact in sample-size planning.

Small samples have one extra wrinkle. With few observations, s itself is uncertain, so the interval should be a bit wider. The t distribution handles this: replace z by T.INV.2T(1-confidence, n-1). With 24 customers and 23 degrees of freedom, t is 2.07 instead of 1.96. Excel also wraps the whole calculation into CONFIDENCE.T(alpha, s, n), which returns the same ±1.43 minutes. For large samples t and z become practically equal, which is why sample-size formulas use z.

The margin of error describes random sampling error only. It does not protect you from a biased sample, for example timing only quiet Tuesday mornings. No sample size fixes a sample that was drawn in the wrong place.

Worked example, part 1: how precise is the pilot?

Larkspur timed 24 customers. The waits range from 0.8 to 13.1 minutes, with most between 2 and 6 minutes and a few long waits on the right. The pilot gives these key numbers:

The pilot in numbers (lab cells E2 to E7)
CellQuantityFormulaResult
E2Confidence levelinput95%
E3Pilot customers timed=COUNT(B2:B25)24
E4Mean wait=AVERAGE(B2:B25)5.38 min
E5Sample standard deviation s=STDEV.S(B2:B25)3.38 min
E6z for 95%=NORM.S.INV(1-(1-E2)/2)1.96
E7Pilot margin of error (t-based)=T.INV.2T(1-E2,E3-1)*E5/SQRT(E3)±1.43 min

So the pilot says: about 5.4 minutes, give or take 1.4. Somewhere between roughly 4 and 7 minutes is a wide range for a client who wants to know whether a new till layout saved a minute. The pilot was never meant to answer the question. Its job is to deliver a realistic estimate of s, the one number you cannot plan without.

Worked example, part 2: from target precision to sample size

Now turn the formula around. If the study should reach a target margin E, solve E = z × s ÷ √n for n: n = (z × s ÷ E)². For E = ±1 minute: (1.96 × 3.38 ÷ 1)² = 43.9, and because you cannot time 0.9 of a customer, and rounding down would miss the target, you round up to 44. In Excel: =ROUNDUP(($E$6*$E$5/G4)^2,0). The table shows all eight target margins of the lab, with the cost at USD 4 per timed customer.

Larkspur Analytics (fictional): required sample size and cost per target margin, s = 3.38 min, 95% confidence, USD 4 per customer
Target MOE (G)Formula in column HRequired n (H)Cost USD (I)Within USD 1,000?
±2=ROUNDUP(($E$6*$E$5/G2)^2,0)1144yes
±1.5=ROUNDUP(($E$6*$E$5/G3)^2,0)2080yes
±1=ROUNDUP(($E$6*$E$5/G4)^2,0)44176yes
±0.75=ROUNDUP(($E$6*$E$5/G5)^2,0)79316yes
±0.5=ROUNDUP(($E$6*$E$5/G6)^2,0)176704yes
±0.4=ROUNDUP(($E$6*$E$5/G7)^2,0)2751,100no
±0.3=ROUNDUP(($E$6*$E$5/G8)^2,0)4891,956no
±0.25=ROUNDUP(($E$6*$E$5/G9)^2,0)7032,812no

Customers needed per target margin (95% confidence)020040060080011±220±1.544±179±0.75176±0.5275±0.4489±0.3703±0.25Target margin of error (minutes)Budget: 250 customers = USD 1,000
Required sample size for each target margin. Mint plans fit the USD 1,000 budget, peach ones do not. The tightest affordable margin is ±0.5 minutes with 176 customers.

The decision falls out of the table. ±0.5 minutes needs 176 customers and costs USD 704, comfortably within the USD 1,000 budget. One step tighter, ±0.4 minutes, already needs 275 customers and USD 1,100. So the smallest affordable margin is ±0.5 minutes, the answer you type into E10 in the lab. Notice what the chart shows: the first steps from ±2 to ±1 minute are cheap, the last ones are brutally expensive.

The square-root law: halving the margin quadruples the sample

Look at two rows of the table: ±1 minute needs 44 customers, ±0.5 minutes needs 176, exactly four times as many. That is not a coincidence. Because n sits under a square root in the margin formula, the margin only halves when n is multiplied by four. To make the answer ten times more precise you would need a hundred times the sample. Cost grows with n, so precision gets expensive fast.

Margin of error shrinks with the square root of n0±0.5±1.0±1.5±2.0±2.50150300450600750Customers timed (n)pilot: n = 24 → ±1.35n = 44 → ±1.00n = 176 → ±0.50n = 703 → ±0.25
Margin of error against sample size for s = 3.38 minutes and 95% confidence (z-based). The curve falls steeply at first and then flattens: each extra customer buys less precision.

This curve is the best argument you can bring into a budget meeting. Going from 24 to 44 customers improves the margin from about ±1.35 to ±1.00 minute, a big gain for 20 extra customers. Going from 176 to 703 customers improves it from ±0.50 to ±0.25, a gain of a quarter of a minute for more than 500 extra customers. Whether that quarter minute is worth USD 2,108 more is a business question, but now everyone at the table sees the price of it.

The sample size depends on the pilot's s, which is itself an estimate from only 24 customers. If the full study turns out more variable, the achieved margin will be wider than planned. Many planners therefore add a safety margin to n, or use a somewhat larger s than the pilot showed, especially when the pilot was small.

Excel worksheet planning a study: pilot wait times, margin of error, required sample size per target margin and study cost
The free lab: from 24 pilot measurements to a study size the budget can pay for.

How to do it in Excel, step by step

  1. Enter or paste the pilot measurements in one column, here B2:B25, with a header in B1. Keep one observation per row and no text in the range.
  2. Set the confidence level in E2 as 95% (Excel stores 0.95). Count the observations in E3 with =COUNT(B2:B25).
  3. Mean in E4: =AVERAGE(B2:B25). Sample standard deviation in E5: =STDEV.S(B2:B25). Do not use STDEV.P; the pilot is a sample, not the whole population of customers.
  4. z in E6: =NORM.S.INV(1-(1-E2)/2). Check that it shows 1.96. If it shows 1.64, you used the one-sided version.
  5. Pilot margin in E7: =T.INV.2T(1-E2,E3-1)*E5/SQRT(E3), or the shortcut =CONFIDENCE.T(1-E2,E5,E3). Expect about 1.43.
  6. Required n in H2: =ROUNDUP(($E$6*$E$5/G2)^2,0). The $ signs lock z and s, while G2 moves as you fill down. Select H2:H9 and press Ctrl+D. H8 (±0.3 minutes) should show 489.
  7. Cost in I2:I9 multiplies n by the price per customer in E8 (the lab already holds =IF(H2="","",H2*$E$8)).
  8. Flag unaffordable plans: select I2:I9, then Home > Conditional Formatting > Highlight Cells Rules > Greater Than, type 1000 (or click E9) and choose Light Red Fill.
  9. Chart it: select G1:H9 and choose Insert > Charts > Column (or press Alt+F1). If Excel plots column G as a second series, use Chart Design > Select Data and set G2:G9 as the horizontal axis labels. Give it a title such as "Customers needed per target margin".
  10. Decide: read down column I to the last cost that is not red, and type its margin, ±0.5, into E10.
To see the trade-off live, add a cell with the budget in customers, =FLOOR(E9/E8,1) = 250, and the best affordable margin directly: =E6*E5/SQRT(FLOOR(E9/E8,1)) gives about ±0.42 minutes. The lab asks for the best margin from the list of targets, which is ±0.5.

Common mistakes and how to spot them

  • STDEV.P instead of STDEV.S. STDEV.P divides by n instead of n − 1 and slightly understates the spread of a sample. The difference is small for large n but real for a 24-customer pilot.
  • Dividing by n instead of √n. =E6*E5/E3 gives about ±0.28 minutes for the pilot, far too optimistic. If a tiny pilot looks amazingly precise, check the square root.
  • One-sided z. =NORM.S.INV(0.95) returns 1.64. For a two-sided 95% interval you need 0.975 inside, giving 1.96. Your sample sizes would be about 30% too small.
  • Rounding down. =ROUND(43.9,0) happens to give 44, but ±0.3 minutes needs 488.2, and ROUND gives 488, which misses the target. Always use ROUNDUP.
  • Forgetting the square in n = (z × s ÷ E)². Without ^2 the ±1 plan shows 7 customers instead of 44. A quick sanity check: halving E must multiply n by about four.
  • Missing $ signs. If H3 suddenly divides by G3 but multiplies by E6 shifted to E7, the numbers jump around. Use Ctrl+` to show formulas and check that z and s are locked.
  • Treating the plan as a guarantee. The achieved margin depends on the real s in the full study. Recompute the margin with CONFIDENCE.T once the data are in, and report that one.

Quick reference: functions and shortcuts used

Quick reference: Excel functions and shortcuts for margin of error and sample size
Function or shortcutWhat it doesExample result
AVERAGE(range)Sample mean5.38
STDEV.S(range)Sample standard deviation (divides by n − 1)3.38
COUNT(range)Number of numeric observations24
NORM.S.INV(0.975)Two-sided z for 95% confidence1.96
T.INV.2T(0.05,23)Two-sided t value for 95% and 23 degrees of freedom2.07
CONFIDENCE.T(0.05,s,n)t-based margin of error in one step1.43
CONFIDENCE.NORM(0.05,s,n)z-based margin of error in one step1.35
ROUNDUP(x,0)Round up to the next whole customer43.9 → 44
SQRT(n)Square root, for the √n in the margin of error4.90
Home > Conditional Formatting > Highlight Cells Rules > Greater ThanFlags costs above the budget> 1,000
Alt+F1Inserts a default chart of the selected datacolumn chart

Real-world uses

  • Customer and service studies. Waiting times, handling times on a hotline, delivery times: any average you want to report "give or take" needs a planned sample size.
  • Quality control. A production engineer decides how many parts to measure to estimate the mean diameter within, for example, ±0.02 mm, using the spread from earlier batches.
  • Surveys and polls. Satisfaction scores, spending per visit or hours worked per week are means; the same square-root law decides how many respondents a precise estimate needs.
  • Budget negotiations. The table of margin versus cost turns "we need more money for research" into a concrete offer: here is what USD 700 buys, here is what USD 2,800 buys.
  • Theses and student projects. A short pilot plus this calculation justifies the planned sample size in the methods section, instead of a vague "we aimed for about 100".

What you will build in the rest of this course

This first lab is free. The remaining 19 labs are part of the full course, a one-time purchase of $9.90, and they take you from estimating one number to planning experiments that can actually detect a difference.

Sample Size for a Proportion & the Finite Population Correction. Many questions are shares, not averages: the percentage of satisfied customers or of defective parts. You size those samples and learn when a small population lets you shrink the sample with the finite population correction.

Effect Size: Pooled SD, Cohen's d & the Minimum Detectable Effect. Before you can size a comparison, you must say how big a difference matters. You measure effect sizes in a way that works across units and set the smallest effect worth detecting.

Sample Size for Comparing Two Means (NORM.S.INV). You size a study that compares two groups, for example old and new till layouts, combining significance level, power and effect size in one formula.

Sample Size for Two Proportions: Sizing an A/B Test. You apply the same logic to conversion rates and find out how many visitors an online A/B test really needs, and why small lifts are so expensive to prove.

The Power Curve: Power vs Sample Size (Scatter Chart). You chart how the chance of detecting an effect grows with the sample size, the picture that makes power analysis intuitive for any audience.

Power and Minimum Detectable Effect for a Fixed Sample Size. Sometimes n is fixed by budget or time. You turn the question around and calculate what that sample can and cannot detect, before you run the study.

Practical Adjustments: Bonferroni, Unequal Allocation, Dropout & Non-Response. Real studies lose participants and test several things at once. You adjust the plan for multiple comparisons, unequal groups, dropout and non-response so the final sample still does its job.

Summary

The margin of error of a mean is z × s ÷ √n. A pilot gives you s, the confidence level gives you z, and the target margin gives you n = (z × s ÷ E)², always rounded up. Because n sits under a square root, halving the margin quadruples the sample and the cost. Put the targets, sample sizes and costs side by side and the right study size becomes a visible, defensible decision.

Now scroll up and run the numbers yourself in the lab: the pilot mean and standard deviation, its margin of error, the required n for eight targets, the budget alert and the chart. It takes about fifteen minutes, and the Coach checks every step.

Frequently asked questions

How do I calculate sample size for a mean in Excel?

Use n = (z × s ÷ E)², where s is the standard deviation from a pilot and E the target margin of error. In Excel: =ROUNDUP((NORM.S.INV(0.975)*s/E)^2,0) for 95% confidence.

How do you calculate the margin of error in Excel?

For a mean, the margin of error is z × s ÷ √n. For small samples use the t distribution with =CONFIDENCE.T(0.05, s, n), which equals =T.INV.2T(0.05,n-1)*s/SQRT(n).

Why does halving the margin of error need four times the sample?

The sample size enters the margin of error under a square root. To halve z × s ÷ √n, √n must double, which means n must be multiplied by four.

Should I round the sample size up or down?

Always round up with ROUNDUP. Rounding down gives a sample that is slightly too small, so the achieved margin of error would miss the target.

Where do I get the standard deviation before the study starts?

From a small pilot study, from earlier comparable data or from published studies on a similar population. Because this value is only an estimate, many planners add a safety margin to the calculated sample size.

What is the difference between CONFIDENCE.NORM and CONFIDENCE.T?

CONFIDENCE.NORM uses the normal z value and CONFIDENCE.T uses the t distribution with n − 1 degrees of freedom. For small samples the t version gives a wider, more honest margin; for large samples they are almost equal.

Keep going: Sample Size & Power Analysis: How Many Observations Do You Need?

This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time $9.90.

  1. Sample Size for a Proportion & the Finite Population Correction
  2. Effect Size: Pooled SD, Cohen's d & the Minimum Detectable Effect
  3. Sample Size for Comparing Two Means (NORM.S.INV)
  4. Sample Size for Two Proportions: Sizing an A/B Test
  5. The Power Curve: Power vs Sample Size (Scatter Chart)
  6. Power and Minimum Detectable Effect for a Fixed Sample Size
  7. Practical Adjustments: Bonferroni, Unequal Allocation, Dropout & Non-Response
  8. Paired Designs: Before-and-After Samples & the Correlation Bonus
  9. Small Samples: Exact Binomial Power vs the Normal Approximation
  10. Cluster Samples: Design Effect, ICC & the Cheapest Cluster Size
  11. Stratified Samples: Proportional vs Neyman Allocation
  12. Sample Size for a Correlation: Fisher's z & Confidence Limits
  13. Sensitivity Grid: When the Planning Assumptions Are Wrong
  14. How Long Must an A/B Test Run? Traffic, Variants & Full Weeks
  15. Project: A Complete Study Plan Dashboard
  16. Count Data: Comparing Two Event Rates & the Exposure You Need
  17. Using a Baseline Covariate: How Much Last Quarter's Data Saves (ANCOVA vs Change Scores)
  18. Fixed Budget, Unequal Costs: the Cost-Optimal Split Between Groups (Chart)
  19. Final Project: A Quarter of A/B Tests – Sizes, Run Times & What Fits

Buy course — $9.90 See the full course