# Sample Size Calculator

> Computes the number of respondents needed to estimate a population proportion within a given margin of error at a given confidence level (Cochran's formula), with an optional finite population correction.

- Calculator id: `sample-size` · Category: Statistics & Probability (`statistics`) · Tool name: `calculate_sample_size`
- Canonical page: https://tttkmbb.com/statistics/sample-size · This document: https://tttkmbb.com/statistics/sample-size.md · JSON definition: https://tttkmbb.com/statistics/sample-size.json

## Purpose

Computes the number of respondents needed to estimate a population proportion within a given margin of error at a given confidence level (Cochran's formula), with an optional finite population correction.

**Use when:** You are planning a survey, poll or A/B test on a proportion and need to know how many people to sample for a target margin of error.

**Do not use when:** You already have a sample and want its margin of error (use margin-of-error), or you are estimating a mean rather than a proportion (the formula would need the standard deviation instead of p(1 − p)).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `confidence_level_percent` | number | % | optional, default 95 | Confidence level in percent (commonly 90, 95 or 99). Determines the critical z value. (> 0) |
| `margin_of_error_percent` | number | % | required | Acceptable half-width of the confidence interval, in percentage points (5 means ±5 %). (> 0, max 50) |
| `expected_proportion_percent` | number | % | optional, default 50 | Anticipated percentage with the attribute. 50 % is the conservative choice giving the largest sample. (min 1, max 99) |
| `population_size` | integer |  | optional | Optional total population size N. When given, the finite population correction is applied; omit for large or unknown populations. (min 2) |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `z_value` | number |  | Two-sided normal critical value for the confidence level. |
| `sample_size` | integer |  | Minimum number of respondents, rounded up; includes the finite population correction when population_size is given. |
| `sample_size_infinite_population` | integer |  | n0 = z² p (1 − p) / e², rounded up, before any finite population correction. |

## Formula

`n0 = z² · p · (1 − p) / e², with p = expected_proportion_percent/100 and e = margin_of_error_percent/100; with population_size N: n = n0 / (1 + (n0 − 1) / N); both rounded up`

Cochran's sample-size formula for a proportion with the normal approximation. The finite population correction is applied to the unrounded n0 (as in most survey references); rounding n0 first would occasionally add one respondent.

## Data Sources

- NIST/SEMATECH e-Handbook of Statistical Methods, 7.2.4.2 Sample sizes required (proportions) — https://www.itl.nist.gov/div898/handbook/prc/section2/prc242.htm (government, retrieved 2026-09-23)
- Wikipedia – Sample size determination — https://en.wikipedia.org/wiki/Sample_size_determination (reference, retrieved 2026-09-23)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/sample-size?margin_of_error_percent=…`
- `POST https://tttkmbb.com/api/v1/calculate/sample-size` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/sample-size · OpenAPI operationId `calculate_sample_size` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "sample-size", "inputs": {…}}`

## Example

- 95 %, ±5 %, p = 50 %: inputs `{"confidence_level_percent":95,"margin_of_error_percent":5,"expected_proportion_percent":50}` → `{"z_value":1.96,"sample_size":385,"sample_size_infinite_population":385}`
- Same, population of 1,000: inputs `{"confidence_level_percent":95,"margin_of_error_percent":5,"expected_proportion_percent":50,"population_size":1000}` → `{"sample_size":278,"sample_size_infinite_population":385}`

```
GET https://tttkmbb.com/api/v1/calculate/sample-size?confidence_level_percent=95&margin_of_error_percent=5&expected_proportion_percent=50
```

## Limitations

You already have a sample and want its margin of error (use margin-of-error), or you are estimating a mean rather than a proportion (the formula would need the standard deviation instead of p(1 − p)). Cochran's sample-size formula for a proportion with the normal approximation. The finite population correction is applied to the unrounded n0 (as in most survey references); rounding n0 first would occasionally add one respondent. All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Why is 385 the usual answer?**

At 95 % confidence, ±5 % margin and p = 50 %: 1.96² × 0.25 / 0.05² = 384.16, rounded up to 385. Halving the margin to ±2.5 % quadruples the sample to 1,537.

**Does the sample size depend on the population size?**

Only when the sample is a noticeable fraction of the population. For a population of 1,000 the correction reduces 385 to 278; for populations above about 100,000 it changes almost nothing.

**What about non-response?**

The result is the number of completed responses. Divide by the expected response rate to get the number of invitations (e.g. 385 / 0.2 = 1,925 for a 20 % response rate).

## Related

- [Margin of Error Calculator](https://tttkmbb.com/statistics/margin-of-error.md) — Margin of error of a sample you already have.
- [Confidence Interval Calculator](https://tttkmbb.com/statistics/confidence-interval.md) — Interval for a mean from a sample.
