Z-Score Calculator

Sample Size Calculator

Z-based formulas using the standard normal distribution. Inverts the confidence-interval formula to solve for n.

Parameter

Pick n so a one-sample CI for μ has margin of error ≤ E. Pairs with the one-sample z-test / CI for mean.

Confidence Level
Mean Parameters

Solution

Share:

Worked Examples

Mean · 95%

Bolt strength: σ = 15, target ME = 2

A factory wants to estimate the mean tensile strength of bolts to within ±2 N at 95% confidence. With known σ = 15 N, what sample size is needed?

  1. z* at 95%: ≈ 1.96.
  2. n ≥ (1.96 × 15 / 2)² = (14.7)² ≈ 216.09.
  3. Round up: n = 217.
  4. Achievable margin at n = 217: 1.96 × 15/√217 ≈ 1.996 — just under target.

Halving the target margin (E = 1) would quadruple n to roughly 865. Precision is expensive.

Proportion · 95%

Election poll: target ME = 3 percentage points, no prior estimate

A pollster wants to estimate voter support to within ±3 percentage points at 95% confidence. With no prior estimate of true support, use the worst-case planning value p̂ = 0.5.

  1. Worst-case planning estimate: p̂ = 0.5 (maximizes p̂(1 − p̂) = 0.25).
  2. z* at 95%: ≈ 1.96.
  3. n ≥ (1.96)² × 0.25 / (0.03)² ≈ 1067.11.
  4. Round up: n = 1068.
  5. Interpret: 1,068 completed responses produce a 95% CI with margin ≤ 0.03 regardless of the true support level.

If a prior poll showed ~60% support, plugging p̂ = 0.6 instead drops n to ~1,024 — about 4% fewer interviews. Tighter priors save sample.

Difference of Means · 95%

Comparing two production lines: σ₁=15, σ₂=12, target ME = 3

Comparing tensile strength between two production lines, you want a 95% CI for the mean difference with margin of error at most 3 N. How many bolts per line?

  1. z* at 95%: ≈ 1.96.
  2. n_each ≥ (1.96)² × (15² + 12²) / 3² = 3.8416 × 369 / 9 ≈ 157.5.
  3. Round up: n_each = 158 per line.
  4. Total: 316 bolts across both lines.
  5. Achievable margin: 1.96 × √(369/158) ≈ 2.99 — just under target.

Equal allocation is most efficient when σ's are similar. With dramatically different σ's, allocate proportional to σ for max efficiency — but the difference is usually small in practice.

Difference of Proportions · 95%

A/B test: prior conversion rates 40% vs 30%, target ME = 5 percentage points

An A/B test compares two variants with prior estimates of 40% and 30% conversion. You want a 95% CI for the lift with margin of error at most 5 percentage points. How many users per variant?

  1. z* at 95%: ≈ 1.96.
  2. n_each ≥ (1.96)² × (0.4×0.6 + 0.3×0.7) / (0.05)² = 3.8416 × 0.45 / 0.0025 ≈ 691.49.
  3. Round up: n_each = 692 per variant.
  4. Total: 1,384 users across both variants.
  5. Achievable margin: ~0.0499 — just under target.

Without prior estimates, planning at p̂₁ = p̂₂ = 0.5 (max variance) bumps n to ~769 per variant. Pilot data is genuinely useful here.

Sample Size for a Mean (known σ)

Choose n so a (1 − α)·100% z-interval for μ has margin of error at most E. Larger σ or stricter E pushes n up; n scales as 1/E², so halving the margin requires four times the sample.

n ≥ (z* × σ / E)²

Sample Size for a Proportion

Choose n so a Wald z-interval for p has margin of error at most E. The product p̂(1 − p̂) maxes out at 0.25 when p̂ = 0.5 — use that as the worst case if you don't have a prior estimate; tighter priors shrink the required n.

n ≥ (z*)² × p̂(1 − p̂) / E²

Sample Size for a Difference of Means

Choose n per group (equal allocation) so a CI for μ₁ − μ₂ has margin of error at most E. Total study size is 2 × n_each. Equal allocation is most efficient when σ's are similar.

n_each ≥ (z*)² × (σ₁² + σ₂²) / E²

Sample Size for a Difference of Proportions

Choose n per group (equal allocation) so a Wald CI for p₁ − p₂ has margin of error at most E. Use prior estimates of p̂₁ and p̂₂ if available, or 0.5 each as the conservative worst case.

n_each ≥ (z*)² × (p̂₁(1 − p̂₁) + p̂₂(1 − p̂₂)) / E²

How It Works

Sample size planning inverts the confidence-interval formula. Start from the CI margin of error: ME = z* × standard error. Substitute the standard error formula for the parameter you're estimating, set ME equal to your target E, and solve for n. The result is rounded up to the next integer because partial subjects don't exist. The planning standard deviation σ (for means) or planning proportion p̂ (for proportions) plugs the otherwise-unknown variance into the formula. Picking 0.5 for an unknown proportion is the worst case — anything else gives a smaller n. Higher confidence (95% → 99%) widens z*, raising n. Tighter margins shrink E, raising n quadratically.

Example Problem

A pollster wants to estimate the proportion of voters supporting a candidate to within ±3 percentage points at 95% confidence. They have no prior estimate of the true support level. How large a sample do they need?

  1. Identify the parameter: a population proportion p.
  2. Pick a planning estimate. With no prior estimate, use the worst case: p̂ = 0.5, which maximizes p̂(1 − p̂) = 0.25.
  3. Find z* at 95% confidence: z_{0.975} ≈ 1.96.
  4. Plug into the formula: n ≥ (1.96)² × 0.25 / (0.03)² = 3.8416 × 0.25 / 0.0009 ≈ 1067.11.
  5. Round up: n = 1068.
  6. Verify: with n = 1068, the achievable margin of error is 1.96 × √(0.5 × 0.5 / 1068) ≈ 0.030 — exactly at the target.
  7. Interpret: a sample of 1,068 voters will produce a 95% CI with margin of error at most ±3 percentage points, regardless of the actual support level.

If a prior poll already showed roughly 60% support, you could plug p̂ = 0.6 into the formula and need only n ≈ 1024 — about 4% fewer interviews. Worst-case planning is conservative; tighter priors save sample.

Key Concepts

Three levers control sample size: confidence level, target margin of error, and the planning estimate of variability. The relationship n ∝ (z*/E)² means precision is expensive — halving the margin quadruples the sample. Higher confidence costs more sample but only modestly: moving from 95% to 99% raises z* from 1.96 to 2.58, raising n by about (2.58/1.96)² ≈ 1.73×. For proportions, p̂ = 0.5 is the worst case; for means, larger σ requires more sample. The result is always rounded up because you can't sample fractional subjects, so the achieved margin will be slightly tighter than the target. For paired or stratified designs the formulas differ; this calculator assumes simple random sampling and (for two-group modes) equal allocation across groups. When σ is unknown and the sample is small, switch to a t-based sample-size calculation.

Applications

  • Polling and election surveys — picking n to bound the margin of error on the headline figure
  • Clinical trial design — sizing each arm so the CI for the treatment effect has acceptable precision
  • A/B testing — picking n per variant so a CI for the lift can detect the smallest meaningful difference
  • Quality control — sizing inspection batches to estimate defect rates within a target tolerance
  • Market research — sizing focus groups or surveys to bound mean estimates within a usable range
  • Manufacturing — sizing production samples to bound mean dimensions within engineering tolerance

Common Mistakes

  • Forgetting to round up — fractional sample sizes don't exist; always ceil the result
  • Using p̂ near 0 or 1 without a strong prior — this shrinks n but the Wald formula is unreliable in those regimes
  • Confusing 'sample size for a CI' with 'sample size for a test with given power' — the latter requires the power 1 − β as an input
  • Picking the wrong z* — confidence level α corresponds to z_{1 − α/2}, not z_{1 − α}
  • Ignoring response rate — the n above is the *completed* sample; oversample to account for dropout or refusal
  • Treating the achievable margin as exactly equal to the target — rounding up always produces a slightly tighter CI than requested

Frequently Asked Questions

What does this calculator answer?

Given a target margin of error E and a confidence level (1 − α), the calculator returns the smallest sample size n such that the corresponding (1 − α)·100% z-interval will have margin of error at most E. It supports four parameter types: a population mean (with σ known), a population proportion, a difference of two means, and a difference of two proportions.

How is this different from a power analysis?

A power analysis for a hypothesis test asks: 'What sample size do I need to detect an effect of size δ with probability 1 − β at significance α?' That formula brings in the test's β as well as its α. Sample size for a CI is simpler and requires only the confidence level and target margin of error — no specified effect size or power.

Why does n scale with the square of 1/E?

The standard error scales as 1/√n. Setting the margin of error E = z* × σ/√n and solving for n gives n = (z* × σ / E)². The square comes from the √n in the denominator. So halving E requires 4× the sample, and quartering E requires 16×. Doubling precision is expensive.

Why use p̂ = 0.5 when I don't have a prior estimate?

p̂(1 − p̂) is maximized at p̂ = 0.5, where it equals 0.25. So 0.5 produces the largest required n — the most conservative answer. Any other value of p̂ yields a smaller n. If you have a prior estimate (from a pilot study, a related population, or domain knowledge), use it to save sample. If not, p̂ = 0.5 guarantees the resulting CI has the requested margin no matter what the true proportion turns out to be.

What if σ is unknown?

For means, the z-formula assumes σ is known. If you only have an estimate, two options: (a) use a pilot study to estimate σ and plug it in, treating the result as approximate; or (b) switch to a t-based sample-size formula, which uses a t critical value and slightly inflates n for small samples. With moderately large planning samples (n > 30) the two approaches converge.

Does this account for dropout or refusal?

No — the n returned is the *completed* sample. If you expect a 20% non-response rate, divide by (1 − 0.20) = 0.80 to get the number to invite or recruit. So a target of 1,000 completed responses with 20% dropout means contacting about 1,250 people.

Why does the calculator assume equal n per group for two-group modes?

Equal allocation is the most efficient design when the two groups have similar variances — it minimizes the standard error of the difference for a fixed total sample size. With very unequal variances the optimal allocation puts more sample in the higher-variance group (proportional to σ), but unequal allocation is rarely worth the operational complexity. This calculator assumes simple equal allocation; you can manually adjust n_each if you have a reason to depart from it.

Can the achievable margin be larger than the target?

No — the calculator rounds up, so the achievable margin is always less than or equal to the target. Rounding down would risk producing an interval slightly wider than requested. The achievable value is reported alongside the recommended n so you can see how much headroom rounding bought you.

Reference: All four sample-size formulas derive from the standard z-based confidence interval formula by setting the margin of error equal to the target E and solving for n. Critical values come from the inverse standard normal CDF (Acklam's rational approximation). The formulas assume simple random sampling, σ or planning p̂ known in advance (or estimated from a pilot), independent observations, and — for two-group modes — equal allocation across groups. Result is always rounded up to the next integer.

Related Calculators

Related Sites