Skip to main content
v2026.11,986 entries · CC-BY 4.0

Sample Size Calculation for Proportions: Formulas, Worked Examples, and Code

Guide to sample size calculation for proportions, covering Cochran’s formula, finite population corrections, statistical power, and Excel, R, and Python code.

Written and maintained by CASRAI Editorial Board

Published

On this page

A sample size calculation for a proportion determines the minimum number of observations or participants required to estimate a population prevalence within a specified margin of error or to detect a statistically significant difference between two proportions. In survey and epidemiological research, estimating a single binomial proportion relies on Cochran’s formula to balance confidence level, expected prevalence, and precision, whereas comparative clinical trials require two-proportion power calculations to guard against both false-positive conclusions (type I error) and underpowered false negatives (type II error).

Definition of sample size calculation for proportions

A sample size calculation for a proportion is the mathematical determination of the sample size necessary to evaluate a dichotomous or categorical variable with predefined statistical precision. Outcomes such as disease prevalence, vaccination compliance, or clinical cure rates represent binomial proportions. Because evaluating an entire population is rarely feasible, investigators sample a subset using simple random sampling to estimate the true population proportion. Sizing depends on whether the design aims for parameter estimation (constructing a confidence interval around a single percentage) or hypothesis testing (detecting a difference between two treatment arms).

Sample size calculation proportion formulas and symbols

The mathematical framework divides into precision-based estimation for descriptive surveys and power-based hypothesis testing for comparative trials.

Cochran’s formula for a single proportion in large populations

For an infinite or large population, Cochran’s sample size formula is:

n₀ = (Z² × p × (1 – p)) / E²

In this equation, each symbol corresponds to a core parameter:

  • n₀: Unadjusted sample size for a large population.
  • Z: Standard normal critical value for the chosen confidence level. For two-sided 95% confidence (α = 0.05), Z = 1.96. For 90% confidence (α = 0.10), Z = 1.645; for 99% confidence (α = 0.01), Z = 2.576.
  • p: Anticipated population proportion. Setting p = 0.50 yields the maximum Bernoulli variance of p(1 – p) = 0.25, ensuring the most conservative sample size when prior prevalence data are unavailable.
  • 1 – p: Complementary proportion (q), representing non-events.
  • E: Specified margin of error (absolute precision), representing the acceptable half-width of the confidence interval (for example, 0.05 for ±5 percentage points).

Finite population correction formula

When target population size N is known and sampling occurs without replacement, the finite population correction (FPC) adjusts the required sample size if n₀ / N exceeds 0.05:

n = n₀ / (1 + (n₀ – 1) / N)

Where N is the finite population size and n is the final corrected sample size. Broader study designs are detailed in sample size determination formulas.

Two-proportion comparison formula for comparative trials

For clinical trials comparing event rates between two independent groups (p₁ versus p₂), Fleiss’s formula computes sample size per arm:

n₁ = n₂ = [Z_(α/2) × √(2 × p̄ × q̄) + Z_β × √(p₁ × q₁ + p₂ × q₂)]² / (p₁ – p₂)²

Where p̄ = (p₁ + p₂) / 2 is the pooled proportion, q̄ = 1 – p̄, Z_(α/2) is the significance threshold (1.96 for α = 0.05), and Z_β corresponds to statistical power (0.8416 for 80% power; 1.2816 for 90% power).

What is margin of error?

The margin of error (E) is the maximum expected difference between the true population proportion and the sample estimate at a specified confidence level. It defines the radius or half-width of the confidence interval around the observed proportion. If a prevalence survey reports 30% with a margin of error of ±4% at a 95% confidence level, the true population value is expected to lie between 26% and 34%.

Margin of error governs sample size through an inverse-square relationship: because E is squared in the denominator of Cochran’s formula, halving E (for example, from 0.06 to 0.03) quadruples the required participant count. Absolute margin of error must not be confused with relative precision; a 5% relative error on a 20% prevalence represents an absolute precision of ±1%, demanding a substantially larger cohort.

How to calculate the standard deviation of a sample proportion

To calculate the standard deviation of a sample proportion, compute the square root of the population variance divided by sample size: σ_p = √((p × (1 – p)) / n). When referencing the sampling distribution across repeated samples, this metric is termed the standard error of the proportion.

The derivation stems from the binomial variance Var(X) = n × p × (1 – p). Because the sample proportion is p̂ = X / n, variance scales by 1 / n²:

  1. Compute Bernoulli variance: Var(unit) = p × (1 – p).
  2. Divide by sample size: Var(p̂) = (p × (1 – p)) / n.
  3. Take the square root: σ_p = √((p × (1 – p)) / n).

When population proportion p is unknown, the sample estimate p̂ yields the estimated standard error: SE(p̂) = √((p̂ × (1 – p̂)) / n). For n = 400 with p̂ = 0.30, SE(p̂) = √(0.21 / 400) ≈ 0.0229 (2.29%).

What is statistical power?

Statistical power (1 – β) is the probability of correctly rejecting a false null hypothesis when a true effect or difference exists. For proportions in clinical trials, power represents the likelihood of detecting a true difference between two groups. The complement, β, is the type II error rate (false negative risk).

Standard research protocols target 80% power (Z_β = 0.8416) or 90% power (Z_β = 1.2816). An underpowered trial has a high risk of missing effective interventions, while overpowering inflates study costs and enrolls patients unnecessarily. Power increases with larger sample sizes, wider differences between proportions, and higher significance thresholds.

How to calculate p value between 2 groups

To calculate the p-value between two groups with proportion outcomes, perform a two-proportion z-test to determine the probability of observing the sample difference under the null hypothesis of equal proportions.

  1. Calculate the pooled proportion: p̄ = (x₁ + x₂) / (n₁ + n₂), where x₁ and x₂ are event counts.
  2. Compute standard error of the difference: SE_diff = √[p̄ × (1 – p̄) × (1 / n₁ + 1 / n₂)].
  3. Compute the Z-statistic: Z = (p₁ – p₂) / SE_diff.
  4. Determine p-value: For a two-tailed test, the p-value is p = 2 × [1 – Φ(|Z|)], where Φ is the standard normal cumulative distribution. Values below α = 0.05 denote statistical significance.

If expected cell counts fall below 5, normal approximation is invalid; Fisher’s exact test should be used instead.

Worked examples with step-by-step arithmetic

The following five worked examples demonstrate sample size calculations across standard investigative scenarios.

Worked example 1: General survey with conservative assumption

A public health team plans a prevalence survey with 95% confidence (Z = 1.96), margin of error ±5% (E = 0.05), and no prior data, setting p = 0.50:

  1. Numerator: Z² × p × (1 – p) = 1.96² × 0.50 × 0.50 = 3.8416 × 0.25 = 0.9604.
  2. Denominator: E² = 0.05² = 0.0025.
  3. Calculation: n₀ = 0.9604 / 0.0025 = 384.16.
  4. Rounding up: n = 385 participants.

Worked example 2: Finite population correction

If conducting the survey within an organization of N = 1,000 employees:

  1. Compute adjustment factor: 1 + (n₀ – 1) / N = 1 + (384.16 – 1) / 1000 = 1 + 0.38316 = 1.38316.
  2. Adjusted size: n = 384.16 / 1.38316 ≈ 277.74.
  3. Rounding up: n = 278 employees (saving 107 surveys).

Worked example 3: Pilot-informed proportion

If pilot literature indicates an expected prevalence of 20% (p = 0.20) at 95% confidence (Z = 1.96) and E = 0.05:

  1. Numerator: 3.8416 × 0.20 × 0.80 = 3.8416 × 0.16 = 0.614656.
  2. Denominator: 0.0025.
  3. Calculation: n = 0.614656 / 0.0025 = 245.86.
  4. Rounding up: n = 246 participants (saving 139 participants versus p = 0.50).

Worked example 4: Comparing two proportions in a clinical trial

A clinical trial tests an experimental regimen with anticipated 40% cure (p₁ = 0.40) versus control 25% (p₂ = 0.25) at α = 0.05 (Z = 1.96) and 80% power (Z_β = 0.8416):

  1. Pooled rate: p̄ = (0.40 + 0.25) / 2 = 0.325; q̄ = 0.675.
  2. First term: 1.96 × √(2 × 0.325 × 0.675) = 1.96 × √0.43875 ≈ 1.29827.
  3. Second term: 0.8416 × √(0.40 × 0.60 + 0.25 × 0.75) = 0.8416 × √0.4275 ≈ 0.55026.
  4. Numerator: (1.29827 + 0.55026)² = (1.84853)² ≈ 3.41708.
  5. Denominator: (0.40 – 0.25)² = 0.15² = 0.0225.
  6. Per-group size: n₁ = n₂ = 3.41708 / 0.0225 ≈ 151.87 → 152 patients per arm (304 total).

Worked example 5: Accounting for participant attrition

If the trial anticipates 10% dropout (d = 0.10):

  1. Enrollment inflation: n_enrolled = n / (1 – d) = 152 / (1 – 0.10) = 152 / 0.90 ≈ 168.89.
  2. Rounding up: 169 patients per arm (338 total) to ensure 152 evaluable completers.

Interpretation and decision guide

The table below summarizes study design scenarios, target populations, and appropriate formulas.

Study Objective Target Population Recommended Formula Required Inputs
Single Prevalence Estimation Large (N > 10,000) Cochran’s Formula Confidence level (Z), Expected proportion (p), Margin of error (E)
Finite Population Survey Small / Finite (N ≤ 10,000) Cochran with FPC Population size (N), Confidence level (Z), Proportion (p), Margin of error (E)
Two-Arm Clinical Trial Independent Cohorts Fleiss Formula Significance (α), Power (1 – β), Rates p₁ and p₂
Multi-Group Comparison (≥ 3 Groups) Multiple Treatment Arms Chi-Square / ANOVA Power Framework Effect size (w or f), Group count (k), Power (1 – β), Significance (α)

Investigators should also evaluate proportion vs percentage to maintain consistent metric definitions across protocol documentation.

Assumptions and common methodological mistakes

Sample size formulas for proportions depend on specific statistical assumptions. Reviewers watch for four common errors:

  • Violating normal approximation assumptions: Standard formulas assume n × p ≥ 10 and n × (1 – p) ≥ 10. For rare proportions (such as p = 0.005), normal approximation produces invalid intervals; exact binomial methods are required.
  • Using survey calculators for comparative trials: Online survey tools (like a Raosoft sample size calculator) compute single-proportion confidence intervals. They do not model comparative hypothesis testing, power, or type II error. Using them for two-arm clinical trials leads to underpowered studies.
  • Confusing margin of error with confidence interval width: Margin of error E represents the half-width (±E). Specifying a 5% total window requires E = 0.025. Entering 0.05 results in one-fourth of the necessary sample size.
  • Ignoring clustering in multi-stage surveys: In cluster sampling (clinics or schools), observations are not independent. Researchers must inflate sample size by the design effect: DEFF = 1 + (m – 1) × ICC, where m is cluster size and ICC is the intracluster correlation coefficient.

How to report sample size in APA style

Methodological reporting standards (APA 7th edition, CONSORT, and STROBE) mandate transparent descriptions of all sizing parameters.

APA single-proportion survey example

“An a priori sample size calculation was conducted to estimate the proportion of patients presenting with medication adherence. Using Cochran’s (1977) formula with an assumed proportion of .50, a 95% confidence level (Z = 1.96), and an absolute margin of error of ±5% (E = .05), a minimum sample of 385 participants was required. To accommodate an anticipated 15% survey non-response rate, recruitment targeted 453 participants (n_adj = 385 / .85). Calculations were executed in R.”

APA two-proportion clinical trial example

“Sample size was determined based on the primary endpoint of 30-day smoking cessation. Anticipated cessation was 20% in the control arm and 35% in the intervention arm (15% absolute risk difference). With two-sided α = .05 (Z = 1.96) and 80% power (1 – β = .80, Z = 0.8416) using Fleiss’s two-proportion formula, 140 patients per arm were required. Accounting for 10% loss to follow-up, target enrollment was set at 156 patients per arm (total N = 312).”

How to calculate sample size in Excel, R, and Python

Automating proportion sample size calculations prevents arithmetic errors across varying parameters.

Sample size calculation proportion Excel implementation

In Microsoft Excel, enter parameters into cells B1 through B4:

  • B1: Confidence Level (e.g., 0.95)
  • B2: Expected Proportion p (e.g., 0.50)
  • B3: Margin of Error E (e.g., 0.05)
  • B4: Population Size N (optional, e.g., 1000)

In cell B5, calculate the unadjusted sample size using:

=ROUNDUP((NORM.S.INV(1 - (1 - B1) / 2)^2 * B2 * (1 - B2)) / (B3^2), 0)

In cell B6, apply the finite population correction using:

=IF(ISBLANK(B4), B5, ROUNDUP(B5 / (1 + (B5 - 1) / B4), 0))

Sample size calculation proportion R implementation

In R, define a function to compute Cochran’s formula with optional FPC:

calc_prop_n <- function(p = 0.50, e = 0.05, conf_level = 0.95, N = Inf) {
  alpha <- 1 - conf_level
  z <- qnorm(1 - alpha / 2)
  n0 <- (z^2 * p * (1 - p)) / (e^2)
  if (is.finite(N)) {
    n_final <- n0 / (1 + (n0 - 1) / N)
  } else {
    n_final <- n0
  }
  return(ceiling(n_final))
}

// Run single proportion survey calculation
n_survey <- calc_prop_n(p = 0.50, e = 0.05, conf_level = 0.95)
print(n_survey) // Returns 385

Sample size calculation proportion Python implementation

In Python, compute sample sizes using standard statistical libraries:

import math
from scipy import stats

def calculate_prop_sample(p=0.50, e=0.05, conf_level=0.95, N=None):
    alpha = 1.0 - conf_level
    z = stats.norm.ppf(1.0 - alpha / 2.0)
    n0 = (z**2 * p * (1.0 - p)) / (e**2)
    if N is not None and math.isfinite(N):
        n_adj = n0 / (1.0 + (n0 - 1.0) / N)
        return math.ceil(n_adj)
    return math.ceil(n0)

// Run calculation for conservative survey
n_required = calculate_prop_sample(p=0.50, e=0.05, conf_level=0.95)
print(f"Required sample size: {n_required}") // Returns 385

Frequently asked questions

How to calculate the standard deviation of a sample proportion?

Calculate the square root of p multiplied by (1 – p) divided by the sample size n: σ_p = √((p × (1 – p)) / n). When estimating from sample data where true p is unknown, substitute observed sample proportion p̂ to determine estimated standard error SE(p̂) = √((p̂ × (1 – p̂)) / n).

What is margin of error?

The margin of error is the maximum expected half-width radius of a confidence interval at a specified confidence level. It quantifies sampling uncertainty by bounding the range within which the true population proportion is expected to fall relative to the sample estimate.

What is statistical power?

Statistical power (1 – β) is the probability of correctly rejecting a false null hypothesis when a true group difference exists. In proportion trials, power standardly targets 80% or 90%, guarding against type II errors where an effective treatment fails to achieve statistical significance.

How to calculate p value between 2 groups?

To calculate the p-value between two proportion groups, execute a two-proportion z-test by computing pooled proportion p̄ = (x₁ + x₂) / (n₁ + n₂), standard error SE_diff = √[p̄(1 – p̄)(1/n₁ + 1/n₂)], test statistic Z = (p₁ – p₂) / SE_diff, and two-tailed probability p = 2 × [1 – Φ(|Z|)].

Why is 0.50 used as the default expected proportion?

The value p = 0.50 is chosen because the Bernoulli variance term p(1 – p) achieves its maximum value of 0.25 at 0.50. This generates the largest required sample size, guaranteeing sufficient statistical precision regardless of the true observed outcome.

When should finite population correction be applied?

The finite population correction should be applied whenever initial sample size n₀ exceeds 5% of the total target population N (n₀ / N > 0.05). Sampling without replacement from a finite pool reduces standard error, lowering required enrollment.

How does a Raosoft sample size calculator differ from clinical trial calculators?

A Raosoft sample size calculator applies Cochran’s single-proportion formula for descriptive surveys. In contrast, clinical trial calculators use two-sample models that incorporate statistical power (1 – β), significance level (α), and minimal detectable effect size between two active comparative arms.

Can an ANOVA sample size calculator be used for proportion outcomes?

No, an ANOVA sample size calculator evaluates continuous outcomes based on variance ratios (F-tests). Binary proportion outcomes must be sized using binomial, chi-square, or logistic regression models rather than ANOVA formulas.

Sources

Data: Sample Size Requirements for Estimating Population Proportions

Comparative dataset detailing required sample sizes for estimating binomial proportions across diverse confidence levels, expected proportions, margins of error, and finite population constraints, compiled using Cochran's formula and finite population corrections.

Period covered: 2026. Coverage: Global.

Sample Size Requirements for Estimating Population Proportions
Study Design ScenarioConfidence Level (%)Critical Value ZAssumed ProportionMargin of Error (%)Finite Population SizeRequired Sample Size (participants)
General Survey (Conservative, Infinite N)951.960.55Infinite385
High-Precision Survey (Conservative, Infinite N)951.960.52Infinite2401
Standard Survey (99% Confidence, Infinite N)992.5760.55Infinite664
Pilot-Informed Survey (20% Prevalence, Infinite N)951.960.25Infinite246
Pilot-Informed Survey (10% Rare Disease, Infinite N)951.960.12Infinite865
Institutional Survey (Conservative, N=1,000)951.960.551000278
Small Community Survey (Conservative, N=500)951.960.55500218
Clinical Audit (80% Compliance Target, N=2,000)951.960.842000323

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Sample Size Calculation for Proportions: Formulas, Worked Examples, and Code

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →