StatsCalculators.com

Margin of Error

Created:April 4, 2025

The Margin of Error Calculator helps you determine the precision of your statistical estimates from sample data. It quantifies the range of values within which the true population parameter is likely to fall. Whether you're analyzing survey results, conducting research, or interpreting polls, this tool helps you understand the reliability of your estimates and report results with appropriate confidence intervals.

Calculator

Parameters

Use 50% for most conservative estimate

Results

Enter values and click calculate to see the margin of error.

What This Means:

For a sample proportion of 50% with sample size 400, the margin of error tells you how much the sample estimate might differ from the true population proportion.

Notes:

  • Margin of error represents the maximum expected difference between your sample estimate and the true population value
  • For proportion calculations, using 50% gives the most conservative (largest) margin of error estimate
  • Higher confidence levels result in larger margins of error
  • The finite population correction (FPC) reduces margin of error when sampling from smaller populations
  • Margin of error only accounts for random sampling error, not other sources of bias

Related Calculators

Learn More

What is Margin of Error?

Margin of error (MOE) represents the maximum expected difference between your sample estimate and the true population parameter. It quantifies the uncertainty associated with sampling and provides a range within which the true population value is likely to fall.

For example, if a political poll shows that 52% of voters support a particular candidate with a margin of error of ±3%, this means the actual level of support in the entire population likely falls between 49% and 55%.

Margin of Error Formula and Example Calculations

Formula:

MOE=z×p(1p)nMOE = z \times \sqrt{\frac{p(1-p)}{n}}
Where:
  • zz = z-score corresponding to your confidence level
  • pp = sample proportion (as a decimal)
  • nn = sample size

Example Calculation:

Given:

  • Sample proportion=70%\text{Sample proportion} = 70\%
  • Sample size=400\text{Sample size} = 400
  • Confidence level=95%(z=1.96)\text{Confidence level} = 95\% (z = 1.96)
MOE=1.96×0.7×0.3400=1.96×0.0229=0.0449=4.49%MOE = 1.96 \times \sqrt{\frac{0.7 \times 0.3}{400}} = 1.96 \times 0.0229 = 0.0449 = 4.49\%

Result: The margin of error is ±4.49%

Finite Population Correction

When sampling from a known, finite population, you can apply the finite population correction:

MOEcorrected=MOE×NnN1MOE_{corrected} = MOE \times \sqrt{\frac{N-n}{N-1}}
Where:
  • NN = population size
  • nn = sample size

Sample Size Formula and Example Calculations

Formula:

n=z2×p(1p)e2n = \frac{z^2 \times p(1-p)}{e^2}
Where:
  • nn = required sample size
  • zz = z-score corresponding to your confidence level
  • pp = expected proportion (as a decimal)
  • ee = desired margin of error (as a decimal)

Example Calculation:

Given:

  • Expected proportion=70%\text{Expected proportion} = 70\%
  • Desired margin of error=5%\text{Desired margin of error} = 5\%
  • Confidence level=95%(z=1.96)\text{Confidence level} = 95\% (z = 1.96)
n=1.962×0.7×0.30.052=3.8416×0.210.0025=0.80670.0025=322.68n = \frac{1.96^2 \times 0.7 \times 0.3}{0.05^2} = \frac{3.8416 \times 0.21}{0.0025} = \frac{0.8067}{0.0025} = 322.68

Result: The required sample size is 323 (rounded up)

Finite Population Correction

When sampling from a known, finite population, you can apply the finite population correction:

ncorrected=n×Nn+N1n_{corrected} = \frac{n \times N}{n + N - 1}
Where:
  • ncorrectedn_{corrected} = corrected sample size
  • nn = uncorrected sample size (calculated above)
  • NN = population size

Maximum Sample Size for Proportion

When the expected proportion is unknown, use p = 0.5 (50%) to calculate the most conservative (largest) sample size:

Example for 95% confidence level and 5% margin of error:

n=1.962×0.5×0.50.052=3.8416×0.250.0025=0.96040.0025=384.16n = \frac{1.96^2 \times 0.5 \times 0.5}{0.05^2} = \frac{3.8416 \times 0.25}{0.0025} = \frac{0.9604}{0.0025} = 384.16

Result: The maximum required sample size is 385 (rounded up)

Interpreting Margin of Error

Correct Interpretation:

If a survey finds that 60% of respondents favor a policy with a margin of error of ±3% at the 95% confidence level:

"We are 95% confident that between 57% and 63% of the population favors the policy."

Common Misinterpretations:

  • Assuming margin of error accounts for all potential errors (it only addresses random sampling error)
  • Interpreting confidence level as the probability the parameter is in the interval (it's about repeated sampling)
  • Applying the same margin of error to subgroups (smaller sample sizes have larger margins of error)
  • Ignoring margins of error when comparing groups (overlapping confidence intervals don't necessarily mean non-significant differences)

Code Implementation

Python Code Example

Python
import numpy as np
from scipy import stats

def margin_of_error_proportion(p, n, confidence_level=0.95, population_size=None):
    
    z = stats.norm.ppf((1 + confidence_level) / 2)
    se = np.sqrt(p * (1 - p) / n)
    moe = z * se
    
    if population_size and population_size > n:
        fpc = np.sqrt((population_size - n) / (population_size - 1))
        moe *= fpc

    return moe * 100

def margin_of_error_mean(std_dev, n, confidence_level=0.95, population_size=None):

    z = stats.norm.ppf((1 + confidence_level) / 2)
    se = std_dev / np.sqrt(n)
    moe = z * se
    if population_size and population_size > n:
        fpc = np.sqrt((population_size - n) / (population_size - 1))
        moe *= fpc
    
    return moe

p = 0.7
n = 400
moe_prop = margin_of_error_proportion(p, n, 0.95)
print(f"Margin of Error for proportion: ±{moe_prop:.2f}%")
# Margin of Error for proportion: ±4.49%

std_dev = 15
n = 100
moe_mean = margin_of_error_mean(std_dev, n, 0.95)
print(f"Margin of Error for mean: ±{moe_mean:.2f}")
# Margin of Error for mean: ±2.94

#---------------------------------------------------#

def sample_size_for_proportion(p, desired_moe, confidence_level=0.95, population_size=None):

    desired_moe_decimal = desired_moe / 100
    z = stats.norm.ppf((1 + confidence_level) / 2)
    n = (z**2 * p * (1-p)) / (desired_moe_decimal**2)
    
    if population_size and population_size > 0:
        n = (n * population_size) / (n + population_size - 1)
    
    return int(np.ceil(n))

def sample_size_for_mean(std_dev, desired_moe, confidence_level=0.95, population_size=None):

    z = stats.norm.ppf((1 + confidence_level) / 2)
    n = (z**2 * std_dev**2) / (desired_moe**2)

    if population_size is not None and population_size > 0:
        n = (n * population_size) / (n + population_size - 1)
    
    return int(np.ceil(n))


moe = 5
p = 0.5
n = sample_size_for_proportion(p, moe)
print(f"Sample size for proportion with {moe}% margin of error: {n}")
# Sample size for proportion with 5% margin of error: 385

std_dev = 15
moe = 3
n = sample_size_for_mean(std_dev, moe)
print(f"Sample size for mean with {moe} margin of error: {n}")
# Sample size for mean with 3 margin of error: 97