Home › Statistics & Probability › Sample Size Calculator
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.
When to use
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)).
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.
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
confidence_level_percent | number | % | default 95 | Confidence level in percent (commonly 90, 95 or 99). Determines the critical z value. Range: > 0 |
margin_of_error_percent | number | % | yes | Acceptable half-width of the confidence interval, in percentage points (5 means ±5 %). Range: > 0, ≤ 50 |
expected_proportion_percent | number | % | default 50 | Anticipated percentage with the attribute. 50 % is the conservative choice giving the largest sample. Range: ≥ 1, ≤ 99 |
population_size | integer | no | Optional total population size N. When given, the finite population correction is applied; omit for large or unknown populations. Range: ≥ 2 |
Outputs
| Output | 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. |
Example
95 %, ±5 %, p = 50 %: {"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: {"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
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/sample-size(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/sample-size · Markdown: https://tttkmbb.com/statistics/sample-size.md · JSON definition: https://tttkmbb.com/statistics/sample-size.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="sample-size" - OpenAPI operationId:
calculate_sample_size - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
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 calculators
- Margin of Error Calculator — Margin of error of a sample you already have.
- Confidence Interval Calculator — Interval for a mean from a sample.