Sample Size Calculator

Proportion Hypothesis Testing

Shaded areas represent Confidence Level (blue) and Alpha tails (red).

Sample Size Formula for Single Proportion

How to Use This Calculator

1. Set Significance (α)

Choose your confidence level. A 95% level (Z=1.96) is the industry standard for most research.

2. Define Margin of Error (E)

Enter the maximum difference you'll allow between the sample and population. Use decimals (e.g., 0.05 for 5%).

3. Estimated Proportion (p̂)

If you have a pilot study or prior data (e.g., 30%), enter 0.30. If you have no idea, leave it blank.

Pro Tip: When you leave the proportion blank, the calculator uses 0.50. This is the "safe" approach because it requires the largest possible sample size to ensure your results are statistically significant.

Sample Size Calculation Examples

Example 1: Unknown Population Proportion

Imagine you are conducting a market research survey to estimate the percentage of people in a city who support a new green policy. Since you don't have prior data, we use the conservative estimate of \(p = 0.5\). To achieve a 95% Confidence Level (\(Z = 1.96\)) and a 5% Margin of Error (\(E = 0.05\)):

\[ n = \frac{(1.96)^2 \cdot 0.5(1 - 0.5)}{0.05^2} = \frac{3.8416 \cdot 0.25}{0.0025} = 384.16 \]

Result: You would need a sample size of 385 people.

Example 2: Using a Pilot Study (Specific \(p\))

Suppose a pilot study shows that roughly 30% (\(p = 0.3\)) of users prefer a dark mode interface. You want to verify this with a 99% Confidence Level (\(Z = 2.576\)) and a tighter 3% Margin of Error (\(E = 0.03\)):

\[ n = \frac{(2.576)^2 \cdot 0.3(1 - 0.3)}{0.03^2} = \frac{6.6358 \cdot 0.21}{0.0009} \approx 1548.35 \]

Result: The required sample size increases to 1,549 due to the higher confidence and lower error requirements.

Sample Size Calculation in R, SAS, and Stata

The same sample size problem can also be addressed using established statistical software. The example below assumes a 95% confidence level, an expected population proportion of 50%, and a desired margin of error of 5%.

n = Z² × p(1 − p) / E²

n = 1.96² × 0.50 × 0.50 / 0.05²
n = 384.16 → 385

RStudio

In R, the standard normal quantile function can be used to reproduce the same normal-approximation calculation directly:

alpha <- 0.05
p <- 0.50
margin <- 0.05

n <- ceiling(qnorm(1 - alpha / 2)^2 * p * (1 - p) / margin^2)
n
# 385

SAS

SAS provides a dedicated PROC POWER procedure for sample size and confidence-interval precision analyses for a single binomial proportion. For example, the following requests a 95% Wilson confidence interval with a half-width of 0.05:

proc power;
    onesamplefreq ci=wilson
        halfwidth = 0.05
        proportion = 0.50
        ntotal = .
        probwidth = 1;
run;

SAS supports several confidence-interval methods for a single proportion, including Wilson, Wald, exact, Jeffreys, and Agresti-Coull intervals. Therefore, the result may differ from the simple normal-approximation formula used by this calculator when a different interval method is selected.

Stata

Stata provides the power oneproportion command for power and sample-size analysis of a one-sample proportion test. Because this is a hypothesis-testing framework rather than a direct margin-of-error calculation, the parameters are specified differently from the formula above. For example:

power oneproportion 0.50 0.55, ///
    power(0.80) test(score)

This Stata example illustrates a related one-sample proportion power analysis, rather than reproducing the 5% confidence-interval margin of error calculation exactly. This distinction is important when comparing sample-size results across statistical software.

Key point: there is no single universal “gold standard” software package for every sample size problem. G*Power, R, SAS, and Stata are all widely used statistical tools, but the statistical method and assumptions selected within the software determine the calculation. For a single population proportion, researchers should report the confidence level, expected proportion, margin of error, and confidence interval or statistical method used.

Related Statistical Calculators