Sample Size Calculator for Research Formula

Understand the math behind the sample size calculator for research. Each variable explained with a worked example.

Formulas Used

Required Sample Size

sample_size = ceil(n_infinite / (1 + (n_infinite - 1) / population))

Sample (Infinite Population)

n_before_correction = ceil(n_infinite)

Variables

VariableDescriptionDefault
confidence_zZ-Score for Confidence Level1.96
margin_of_errorMargin of Error0.05
proportionExpected Proportion0.5
populationPopulation Size10000
n_infiniteDerived value= pow(confidence_z, 2) * proportion * (1 - proportion) / pow(margin_of_error, 2)calculated

How It Works

How to Calculate Sample Size

The sample size formula balances precision against cost. A larger sample reduces the margin of error but requires more resources.

Formula (Cochran's)

n_0 = Z^2 x p x (1 - p) / E^2

With finite population correction:

n = n_0 / (1 + (n_0 - 1) / N)

Where Z is the z-score for your confidence level, p is the expected proportion, E is margin of error, and N is population size.

Using p = 0.5 gives the most conservative (largest) sample size when the true proportion is unknown.

Worked Example

A researcher needs 95% confidence (Z = 1.96), 5% margin of error, expected proportion 0.5, population 10,000.

confidence_z = 1.96margin_of_error = 0.05proportion = 0.5population = 10000
  1. 01n_0 = 1.96^2 x 0.5 x 0.5 / 0.05^2 = 3.8416 x 0.25 / 0.0025 = 384.16
  2. 02Finite correction: 384.16 / (1 + 383.16 / 10000) = 384.16 / 1.0383 = 370
  3. 03Required sample size: 370