---
title: "Calculate the confidence interval for a sample mean. Given a sample mean, sample size, standard deviation, and confidence level, computes the margin of error, lower and upper bounds, critical z-score, and standard error. Supports finite population correction (FPC) when a population size is provided, which narrows the interval for samples that are a large fraction of the population. Uses the Abramowitz & Stegun rational approximation for the inverse normal CDF to derive the critical z-value. Common in survey analysis, A/B testing, and quality control."
method: POST
path: "/api/confidence_interval"
tags: ["general"]
---

# Calculate the confidence interval for a sample mean. Given a sample mean, sample size, standard deviation, and confidence level, computes the margin of error, lower and upper bounds, critical z-score, and standard error. Supports finite population correction (FPC) when a population size is provided, which narrows the interval for samples that are a large fraction of the population. Uses the Abramowitz & Stegun rational approximation for the inverse normal CDF to derive the critical z-value. Common in survey analysis, A/B testing, and quality control.

`POST /api/confidence_interval`

## Request

- Base URL: `https://calc.engineer`
- URL: `https://calc.engineer/api/confidence_interval`
- Auth: none declared

## Request body

- object
  - `sample_mean` number, required: The observed sample mean (x-bar) around which the confidence interval is centered.
  - `sample_size` number, required: The number of observations in the sample (n). Must be a positive integer.
  - `standard_deviation` number, required: The standard deviation of the sample or population. Must be a positive number.
  - `confidence_level` number: Confidence level as a decimal between 0 and 1 (e.g. 0.95 for 95%). Default is 0.95.
  - `population_size` number: Total population size for finite population correction (FPC). Omit for infinite population assumption.

## Response `200`

Computed result for confidence_interval

- object
  - `result` object, required
    - `lower_bound` number, required: Lower bound of the confidence interval.
    - `upper_bound` number, required: Upper bound of the confidence interval.
    - `margin_of_error` number, required: Half-width of the confidence interval (z_score * standard_error).
    - `z_score` number, required: Critical z-value used for the given confidence level.
    - `standard_error` number, required: Standard error of the mean, optionally adjusted with finite population correction.
    - `confidence_level` number, required: The confidence level used (echoed back).
  - `tool` string, required
  - `version` string, required
  - `computed_at` string, date-time, required
  - `chain` object, required
    - `feeds` unknown[]
      - unknown
    - `accepts_from` unknown[]
      - unknown

## Other responses

- `400`: Validation error or invalid JSON
- `404`: Tool not found

---

[API](https://skmtc.dev/calc/apis/calc-engineer-api.md) · [All operations](https://skmtc.dev/calc/apis/calc-engineer-api/llms.txt) · [OpenAPI document](https://skmtc.dev/calc/apis/calc-engineer-api/revisions/8830480ec488?raw)
