Sample Size Confidence Interval Calculator

When designing a study or survey you need two things up front: how precise you want your estimate to be and how confident you want to be in that precision. A Sample Size / Confidence Interval Calculator converts those choices (confidence level and margin of error) into the number of observations you should collect. This guide explains the formulas, shows step-by-step arithmetic examples for means and proportions, covers practical adjustments (finite population, pilot studies, design effect), and answers 20 common questions so you can plan a statistically sound study.

Sample Size & Confidence Interval Calculator

Quick overview — What the calculator gives you

  • Required sample size for estimating a population mean (when you know or can estimate the standard deviation).
  • Required sample size for estimating a population proportion (e.g., percent who support X).
  • Optional finite-population correction when the population is small.
  • Suggested adjustments when the standard deviation is unknown, or when using complex survey designs.

Plain-text formulas

1) Sample size for a mean (known σ)

When the population standard deviation (σ) is known or can be approximated:

iniCopyEditn = (Z * σ / E)^2 

Where:

  • n = required sample size (round up to next whole number)
  • Z = Z-score for desired confidence (e.g., 1.96 for 95%)
  • σ = estimated population standard deviation
  • E = margin of error (half the width of the confidence interval, in same units as the mean)

2) Sample size for a proportion

For estimating a proportion p (when p is unknown, use 0.5 for maximum variance):

iniCopyEditn = p*(1 − p) * (Z / E)^2 

Where p is the estimated proportion (use 0.5 if uncertain).

3) Finite population correction (FPC)

If the population size N is not huge relative to n, adjust:

iniCopyEditn_adj = (N * n0) / (N + n0 − 1) 

Where n0 is the sample size from one of the formulas above.

4) When σ unknown (small samples)

If σ is unknown, you may:

  • Use a pilot study to estimate s and plug into the mean formula (using Z is common for planning), or
  • Use t critical values iteratively if you want exact small-sample control (practical planning usually uses Z with pilot s).

5) Design effect (complex sampling)

For cluster or stratified designs, multiply by DEFF (design effect):

iniCopyEditn_effective = n × DEFF 

How to use the calculator (step-by-step)

  1. Choose metric: mean (continuous outcome) or proportion (binary outcome).
  2. Pick confidence level: common choices 90% (Z ≈ 1.645), 95% (Z ≈ 1.96), 99% (Z ≈ 2.576).
  3. Specify margin of error (E): how far the sample estimate can be from the true value (same units for means; proportion in decimal for p).
  4. Enter estimate of σ (for means) or p (for proportions). If unknown, use conservative values (σ from previous studies; p = 0.5).
  5. (Optional) enter population size N for finite population correction.
  6. (Optional) enter design effect DEFF if sampling is not simple random.
  7. Calculate: the tool returns n (and adjusted n if FPC or DEFF used). Round up to the next integer.

Worked examples (digit-by-digit arithmetic — follow carefully)

Example A — Sample size for a mean

You plan a survey for average daily screen time. From prior research you estimate σ = 12 minutes. You want a 95% confidence interval and a margin of error E = 3 minutes.

  1. Z for 95%: 1.96
  2. Compute Z * σ:
    • 1.96 × 12 = 23.52
  3. Divide by E:
    • 23.52 ÷ 3 = 7.84
  4. Square:
    • 7.84^2 = 7.84 × 7.84 = 61.4656
  5. Round up:
    • n = 62

Interpretation: You need at least 62 observations to estimate mean screen time within ±3 minutes with 95% confidence.


Example B — Sample size for a proportion

You want to estimate the proportion of customers who will recommend a product. You want 95% confidence, margin of error E = 0.05 (±5%). No prior estimate for p, so use p = 0.5 (most conservative).

  1. Z for 95%: 1.96
  2. Compute Z / E:
    • 1.96 ÷ 0.05 = 39.2
  3. Square that:
    • 39.2^2 = 1,536.64
  4. Multiply by p(1−p):
    • 0.5 × (1 − 0.5) = 0.5 × 0.5 = 0.25
    • 0.25 × 1,536.64 = 384.16
  5. Round up:
    • n = 385

Interpretation: With no prior info, survey 385 people to estimate a proportion within ±5% at 95% confidence.


Example C — Finite population correction

You’re sampling a class of N = 400 students and the proportion formula above gave n0 = 385. For small populations the corrected sample size is:

  1. Plug into FPC formula:
    • n_adj = (N × n0) / (N + n0 − 1)
  2. Compute numerator:
    • N × n0 = 400 × 385 = 154,000
  3. Compute denominator:
    • N + n0 − 1 = 400 + 385 − 1 = 784
  4. Divide:
    • 154,000 ÷ 784 = 196.428571…
  5. Round up:
    • n_adj = 197

Interpretation: Instead of 385, you only need 197 students because the population (400) is small.


Example D — Unknown σ, use pilot estimate

You don’t know σ for hours studied per week. You run a pilot with 25 students and compute sample standard deviation s = 8. Use the mean formula with s as σ estimate, 95% CI and E = 2 hours:

  1. Z = 1.96
  2. Z × s = 1.96 × 8 = 15.68
  3. ÷ E: 15.68 ÷ 2 = 7.84
  4. Square: 7.84^2 = 61.4656
  5. Round up: n = 62

(If you want to be conservative, add 10–20% for nonresponse.)


Practical advice and caveats

  • Round up sample sizes — you can’t collect fractional respondents.
  • Nonresponse & missing data: inflate n by (1 / response_rate). Example: if expected response 80%, divide required n by 0.8.
  • p = 0.5 is conservative for proportions; if you have prior data (say p≈0.2), use it — required n falls.
  • Design effect (DEFF): cluster sampling increases variance. If DEFF = 1.5, multiply n by 1.5.
  • Margins and costs tradeoff: smaller E requires much larger n (n grows with 1/E^2). Doubling precision (halving E) quadruples sample size.
  • Use t-values for small planned n if you insist on exact coverage, but planning usually uses Z with pilot s — it’s simpler and common practice.

20 Frequently Asked Questions (FAQs)

  1. What’s the difference between margin of error and confidence level?
    Margin of error (E) is precision; confidence level (e.g., 95%) is how often the CI would contain the true value in repeated samples.
  2. Why use Z instead of t when planning sample size?
    Z is standard for planning; t depends on unknown n. Using Z with a pilot s is practical for planning.
  3. Why use p = 0.5 for proportions?
    p = 0.5 maximizes p(1−p) and yields the largest required n (conservative).
  4. How does required n change if I halve E?
    Required n multiplies by 4 (since n ∝ 1/E^2).
  5. What is finite population correction and when to use it?
    Use FPC when sample is a substantial fraction (say >5–10%) of the population; it reduces required n.
  6. How to account for expected nonresponse?
    Divide the calculated n by the expected response rate (e.g., if 70% respond, multiply n by 1/0.7 ≈ 1.43).
  7. Can I use the calculator for means with skewed data?
    For heavy skew or outliers, consider a larger sample or transform the data; the formulas assume approximate normality of the estimator.
  8. What if I need subgroup estimates?
    Calculate n for each subgroup separately — you need sufficient n in each subgroup.
  9. Is there a minimum n for central limit theorem to hold?
    No universal threshold, but n ≥ 30 is a common rule-of-thumb; smaller n may still be fine if the data are normal.
  10. How do I select σ if I have no pilot?
    Use prior studies, domain expertise, or conservative guesses; larger σ means larger n.
  11. Does the formula change for one-sided intervals?
    Yes — a one-sided confidence uses a different Z (smaller), so n would be slightly smaller.
  12. What is design effect (DEFF)?
    DEFF adjusts for sampling methods that increase variance (e.g., cluster sampling). Multiply n by DEFF.
  13. Can I plan sample size for estimating a mean difference?
    Yes — that uses a different formula involving both group variances and the effect size you want to detect.
  14. How precise is the calculator result?
    It’s as accurate as your inputs (σ or p). Garbage in → garbage out.
  15. Should I always round up?
    Yes — rounding up ensures your desired precision.
  16. Can I use these formulas for rates or counts?
    For rare events or counts, use Poisson or other specialized formulas.
  17. Does stratification reduce required sample size?
    Stratified sampling can increase efficiency if strata are homogeneous; it may reduce overall n.
  18. Should I plan for ethical or practical constraints?
    Yes — budget, time, and ethics (e.g., survey fatigue) can limit feasible n.
  19. How to include multiple outcomes?
    Calculate n for each primary outcome and choose the maximum.
  20. Is software available for iterative/t-based planning?
    Yes — many stats packages and online tools can do t-based iterative sample-size estimation; for planning the Z-based formulas are sufficient.