{
  "id": "sample-size",
  "version": "9c20e9f735ec",
  "status": "published",
  "name": "Sample Size Calculator",
  "question": "What sample size do I need?",
  "summary": "Computes the sample size for a survey proportion or a mean at a margin of error and confidence level, with a finite population, or per group to compare two means or two proportions with a given power.",
  "category": "statistics",
  "subcategory": "tests",
  "url": "https://www.acalculator.org/statistics/sample-size-calculator",
  "markdown": "https://www.acalculator.org/statistics/sample-size-calculator.md",
  "kind": "function",
  "method": "Proportion: n₀ = z² p(1 − p) ÷ E². Mean: n₀ = (z σ ÷ E)². Finite population: n = n₀ ÷ (1 + (n₀ − 1) ÷ N). Two means: n = 2 (z(α/2) + z(β))² σ² ÷ Δ² per group. Two proportions: n = (z(α/2) + z(β))² (p₁q₁ + p₂q₂) ÷ (p₁ − p₂)² per group. Round up.",
  "assumptions": [
    "Simple random sampling. The z values are exact standard normal quantiles (1.959964, not 1.96).",
    "The comparisons use a two-sided test at level α and groups of equal size.",
    "Every sample size is rounded up to the next whole number."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "goal": {
        "title": "I want to",
        "description": "Estimate a proportion (a survey) or a mean to a margin of error, or compare two groups’ means or proportions with a test.",
        "type": "string",
        "enum": [
          "proportion",
          "mean",
          "twoMeans",
          "twoProportions"
        ]
      },
      "cl": {
        "title": "Confidence level",
        "description": "How confident the margin of error is, in percent: 95 for 95%.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 1,
        "maximum": 99.9999
      },
      "moe": {
        "title": "Margin of error",
        "description": "The largest acceptable difference between the sample result and the truth, in percentage points: 5 for ±5%.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 0.0001,
        "maximum": 50
      },
      "p": {
        "title": "Expected proportion",
        "description": "Your best guess of the proportion, in percent. Use 50 when unsure: it gives the largest sample.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 0.0001,
        "maximum": 99.9999
      },
      "sigma": {
        "title": "Standard deviation (σ)",
        "description": "The expected standard deviation of the measurement, from a pilot study or past data.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000000
      },
      "e": {
        "title": "Margin of error",
        "description": "The largest acceptable difference between the sample mean and the true mean, in the same units as σ.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000000
      },
      "pop": {
        "title": "Population size",
        "description": "How many are in the whole population. Leave empty for a very large or unknown population.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000000000
      },
      "delta": {
        "title": "Difference to detect (Δ)",
        "description": "The smallest difference between the two means worth detecting, in the same units as σ.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000000
      },
      "p1": {
        "title": "Proportion in group 1",
        "description": "The expected proportion in the first group, in percent.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 0.0001,
        "maximum": 99.9999
      },
      "p2": {
        "title": "Proportion in group 2",
        "description": "The expected proportion in the second group, in percent.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 0.0001,
        "maximum": 99.9999
      },
      "alpha": {
        "title": "Significance level (α)",
        "description": "The two-sided significance level of the test, for example 0.05.",
        "type": "number",
        "minimum": 1e-10,
        "maximum": 0.5
      },
      "power": {
        "title": "Power",
        "description": "The chance of detecting the difference when it is real, in percent: 80 is common.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 50,
        "maximum": 99.9999
      }
    }
  },
  "outputs": {
    "n": {
      "label": "Sample size",
      "description": "The number to sample, rounded up: in total for an estimate, or in each group for a comparison.",
      "format": "integer"
    },
    "scope": {
      "label": "Sample size is",
      "description": "Whether the sample size is in total or in each of the two groups.",
      "format": "text"
    },
    "total": {
      "label": "Total for both groups",
      "description": "Twice the sample size per group. Shown for comparisons.",
      "format": "integer"
    },
    "exact": {
      "label": "Before rounding up",
      "description": "The sample size from the formula, before it is rounded up to a whole number.",
      "format": "number"
    },
    "infinite": {
      "label": "For a very large population",
      "description": "The sample size before the finite population correction, rounded up. Shown when a population size is given and it is at most 10¹⁵.",
      "format": "integer"
    },
    "z": {
      "label": "z for the confidence level",
      "description": "The standard normal value with an upper tail of (1 − confidence) ÷ 2, or of α ÷ 2 for a comparison.",
      "format": "number"
    },
    "zPower": {
      "label": "z for the power",
      "description": "The standard normal value with an upper tail of 1 − power. Shown for comparisons.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "goal": "proportion",
      "cl": 95,
      "moe": 5,
      "p": 50,
      "sigma": 15,
      "e": 3,
      "delta": 5,
      "p1": 60,
      "p2": 45,
      "alpha": 0.05,
      "power": 80
    },
    "outputs": {
      "n": 385,
      "scope": "in total",
      "exact": 384.1458820694131,
      "z": 1.9599639845400558
    },
    "text": "You need a sample size of 385 in total."
  },
  "examples": [
    {
      "given": {
        "goal": "proportion",
        "cl": 95,
        "moe": 5,
        "p": 50
      },
      "expect": {
        "n": 385,
        "exact": 384.1458820694127,
        "z": 1.9599639845400545
      },
      "source": "Israel, Determining Sample Size, University of Florida IFAS Extension PEOD6, 1992 (Cochran’s formulas). https://ask.ifas.ufl.edu/publication/PD006 (n₀ = 1.96² × 0.5 × 0.5 ÷ 0.05² = 385)"
    },
    {
      "given": {
        "goal": "proportion",
        "cl": 95,
        "moe": 5,
        "p": 50,
        "pop": 2000
      },
      "expect": {
        "n": 323,
        "infinite": 385,
        "exact": 322.38553666369626
      },
      "source": "Israel, Determining Sample Size, University of Florida IFAS Extension PEOD6, 1992 (Cochran’s formulas). https://ask.ifas.ufl.edu/publication/PD006 (385 ÷ (1 + 384 ÷ 2000) = 323)"
    },
    {
      "given": {
        "goal": "mean",
        "cl": 95,
        "sigma": 15,
        "e": 3
      },
      "expect": {
        "n": 97,
        "exact": 96.03647051735318
      },
      "source": "hand calculation in content.mdx: (1.959964 × 15 ÷ 3)² = 96.04; Israel, Determining Sample Size, University of Florida IFAS Extension PEOD6, 1992 (Cochran’s formulas). https://ask.ifas.ufl.edu/publication/PD006"
    },
    {
      "given": {
        "goal": "twoMeans",
        "sigma": 10,
        "delta": 5,
        "alpha": 0.05,
        "power": 80
      },
      "expect": {
        "n": 63,
        "total": 126,
        "exact": 62.79103787479273,
        "zPower": 0.8416212335729142
      },
      "source": "hand calculation in content.mdx: 2 × (1.959964 + 0.841621)² × 10² ÷ 5² = 62.79; Noordzij et al., Sample size calculations: basic principles and common pitfalls, Nephrology Dialysis Transplantation, 2010. https://doi.org/10.1093/ndt/gfp732"
    },
    {
      "given": {
        "goal": "twoProportions",
        "p1": 60,
        "p2": 45,
        "alpha": 0.05,
        "power": 80
      },
      "expect": {
        "n": 171,
        "total": 342,
        "exact": 170.059060910897
      },
      "source": "hand calculation in content.mdx: 7.84888 × (0.24 + 0.2475) ÷ 0.15² = 170.06; Noordzij et al., Sample size calculations: basic principles and common pitfalls, Nephrology Dialysis Transplantation, 2010. https://doi.org/10.1093/ndt/gfp732"
    },
    {
      "given": {
        "goal": "mean",
        "cl": 95,
        "sigma": 1,
        "e": 1
      },
      "expect": {
        "n": 4
      },
      "source": "hand calculation in content.mdx: 1.959964² = 3.8415, rounded up to 4; NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2.2 Sample sizes required. https://www.itl.nist.gov/div898/handbook/prc/section2/prc222.htm"
    }
  ],
  "sources": [
    "Israel, Determining Sample Size, University of Florida IFAS Extension PEOD6, 1992. https://ask.ifas.ufl.edu/publication/PD006",
    "NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2.2 Sample sizes required. https://www.itl.nist.gov/div898/handbook/prc/section2/prc222.htm",
    "Noordzij et al., Sample size calculations: basic principles and common pitfalls, Nephrology Dialysis Transplantation, 2010. https://doi.org/10.1093/ndt/gfp732"
  ],
  "related": [
    "confidence-interval",
    "t-test",
    "z-score",
    "standard-deviation"
  ],
  "changelog": []
}
