{
  "schemaVersion": 1,
  "slug": "sample-size-calculator",
  "category": "statistics",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "ae06836a51406902259e6b12bd9ea738d7b958679218523a7627c51d83cd1f89",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/sample-size-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "n0 = z²p(1 - p) ÷ e²; n = n0 ÷ (1 + (n0 - 1) ÷ N)",
    "vars": [
      [
        "z",
        "Z-score for confidence"
      ],
      [
        "p",
        "Expected proportion 0–1"
      ],
      [
        "e",
        "Margin of error 0–1"
      ],
      [
        "N",
        "Population (0 = unlimited)"
      ],
      [
        "n",
        "Sample size"
      ]
    ],
    "note": "Uses a two-sided normal z estimate for the selected confidence level and margin of error. The finite-population correction is applied to both the entered proportion and the worst-case 50% estimate when population is known; population 0 means unknown/large. Required counts are rounded up."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-12",
    "sources": [
      {
        "name": "NIST — Confidence intervals and sampling assumptions",
        "url": "https://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm"
      }
    ],
    "referenceRole": "context",
    "implementationHash": "ae06836a51406902259e6b12bd9ea738d7b958679218523a7627c51d83cd1f89",
    "basis": "n0 = z²p(1 - p) ÷ e²; n = n0 ÷ (1 + (n0 - 1) ÷ N)",
    "limitations": "The references provide context and limitations. They do not validate this page’s illustrative multipliers, lookup values or predictions."
  },
  "contract": {
    "compute": "const Z={80:1.2816,90:1.6449,95:1.96,99:2.5758}; const z=Z[Number(confidence)]||1.96; const p=proportion/100,e=marginOfError/100,N=Number(population); if(e<=0||p<0||p>1||N<0)return{sampleSize:null,baseSampleSize:null,correctionFactor:null,worstCaseSampleSize:null,__error:'inputError'}; const n0=z*z*p*(1-p)/(e*e); const nWorst=z*z*0.25/(e*e); const adjusted=N===1?1:N>1?n0/(1+(n0-1)/N):n0;const worstAdjusted=N===1?1:N>1?nWorst/(1+(nWorst-1)/N):nWorst; return{sampleSize:Math.ceil(adjusted),baseSampleSize:Math.ceil(n0),correctionFactor:n0>0?adjusted/n0:1,worstCaseSampleSize:Math.ceil(worstAdjusted)};",
    "inputs": [
      {
        "name": "confidence",
        "type": "select",
        "default": 95,
        "options": [
          {
            "value": 80
          },
          {
            "value": 90
          },
          {
            "value": 95
          },
          {
            "value": 99
          }
        ]
      },
      {
        "name": "marginOfError",
        "type": "number",
        "default": 5,
        "min": 0.5,
        "max": 20,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "proportion",
        "type": "number",
        "default": 50,
        "min": 1,
        "max": 99,
        "step": 1,
        "slider": true
      },
      {
        "name": "population",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 2000000000,
        "step": 100
      }
    ],
    "outputs": [
      {
        "name": "sampleSize",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "baseSampleSize",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "correctionFactor",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "worstCaseSampleSize",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
