Z-test calculator
Check whether a sample mean fits a hypothesized mean when the population standard deviation is known: a mean of 105 against 100, with a standard deviation of 15 and 36 observations, gives a standard error of 2.5 and a z of 2. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Sample mean
- 105
- Population mean
- 100
- Std
- 15
- N
- 36
- Se
- 2.5
- Z
- 2
- P value
- 0.0455001258
- Tails
- Two
A one-sample z-test asks whether an observed sample mean is compatible with a hypothesized population mean when the population standard deviation is treated as known. The test compresses those four numbers into a single z-statistic: the signed distance of the sample mean from the hypothesized value, measured in units of the standard error sigma over square root of n. This z-test calculator returns that z-statistic together with the matching p-value so you can judge the result against a conventional significance level. The default p-value is two-tailed; optional left and right tails cover one-sided alternatives. A standard deviation that is not strictly positive is rejected, because the standard error would not be a usable scale. Sample size must be a positive integer.
How the z-statistic is formed from mean, sigma, and n
Write the null hypothesis as the population mean equals a hypothesized value mu-zero, and write the alternative as not-equal, less-than, or greater-than according to the tail you choose. The sampling variability of a mean computed from n independent observations with known population standard deviation sigma is summarized by the standard error: sigma divided by the square root of n. Subtract the hypothesized population mean from the observed sample mean and divide by that standard error.
The quotient is the z-statistic. Zero means the sample landed exactly on the hypothesized value. Plus two means the sample mean sits two standard errors above the hypothesized mean; minus two means two standard errors below.
Because the sampling distribution of the mean is treated as normal with that standard error, the z-statistic is compared to the standard normal curve to produce a p-value. This capability performs only that arithmetic. It does not estimate sigma from a raw list of observations, it does not switch to a t-distribution when n is small, and it does not compute power or a required sample size; those are different search intents.
Sample size n must be an integer of at least one so the square-root term is defined.
Input contract, p-values, and what a rejected sigma looks like
Optionally set tails to two, left, or right. The default two is the two-sided test whose p-value is twice the upper standard-normal tail beyond the absolute value of z. Left uses the lower tail Phi of z for the alternative that the true mean is smaller than mu-zero.
Right uses one minus Phi of z for the alternative that the true mean is larger. A non-integer or non-positive n fails the same way. A classic classroom check is sample mean one hundred five against a hypothesized mean of one hundred, sigma fifteen, and n thirty-six: the standard error is two point five, z equals two, and the two-tailed p-value is about four and a half percent.
What you can do with it
Classroom and homework z-tests for a mean
Check textbook one-sample z-tests: plug in x-bar, hypothesized μ0, known σ, and n, then verify the z-statistic and two-tailed p-value against the answer key.
Process mean versus a known process sigma
Compare a batch sample mean with a process target when historical σ is known, and read the p-value without rebuilding the standard-error formula in a spreadsheet.
LMS auto-grading of hypothesis-test items
Mark z-test questions with a deterministic oracle that rejects non-positive σ and never invents a p-value when the standard error would be undefined.
FAQ
What is the formula for the one-sample z-test?
z = (x̄ − μ0) / (σ / √n), where x̄ is the sample mean, μ0 is the hypothesized population mean, σ is the known standard deviation, and n is the sample size. The p-value is taken from the standard normal curve Φ.
What happens if the standard deviation is zero or negative?
The z-test is undefined when σ is not strictly positive, because the standard error σ/√n would not be a usable scale.
When should I use a z-test instead of a t-test?
Use this z-test when the population standard deviation is treated as known. If you only have a sample standard deviation, a t-test with n−1 degrees of freedom is the matching procedure and is a different calculator.
What does the z-test calculator cost?
The browser tool is free and runs locally.
Should I use a two-tailed or a one-tailed z-test?
Use the default two-tailed test when any difference matters. Choose the left tail if your alternative says the true mean is smaller than the hypothesized one, and the right tail if it says the true mean is larger.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/stat/z-test \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"sample_mean":105,"population_mean":100,"std":15,"n":36}'const res = await fetch("https://api.kit.forhosting.com/stat/z-test", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"sample_mean": 105,
"population_mean": 100,
"std": 15,
"n": 36
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/z-test",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"sample_mean": 105,
"population_mean": 100,
"std": 15,
"n": 36
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/z-test", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"sample_mean":105,"population_mean":100,"std":15,"n":36}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"sample_mean":105,"population_mean":100,"std":15,"n":36}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/z-test", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"sample_mean": 105,
"population_mean": 100,
"std": 15,
"n": 36
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.z_test",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
How the z-statistic is formed from mean, sigma, and n
The only hard mathematical constraint on sigma is that it must be strictly positive: a zero or negative standard deviation would make the standard error undefined or meaningless and is rejected with invalid_input.
Input contract, p-values, and what a rejected sigma looks like
Send four required finite numbers: sample_mean (the observed x-bar; aliases xbar and x_bar), population_mean (the hypothesized mu-zero; aliases mu, mu0, and hypothesized_mean), std (the known population standard deviation; aliases sd, standard_deviation, and sigma), and n (the sample size; aliases sample_size and size). Missing fields, non-numeric strings, NaN, and Infinity fail with invalid_input naming the field and are not billed. On success the body echoes the cleaned inputs, returns se (the standard error), z (the z-statistic), p_value, the tails actually used, and a short formula string. Pair that JSON with your own significance threshold; this endpoint does not decide reject or fail to reject, it only returns z and p. API pricing for a successful call is the published base of $0.002 per item.
Where a one-sample z-test calculator shows up in real work
Quality-control teams compare a batch mean against a process target when the process sigma is known from a long control history, and they need the same z and p-value the textbook formula produces rather than an opaque spreadsheet cell. Product and research groups sometimes treat a published population mean and sigma as the null when a new sample of n observations is in, and they want a two-tailed p-value before they escalate to a fuller t-test or a confidence interval. If you later need a t-test from sample standard deviation, a z-score for a single raw value, a normal CDF table, or two-tailed critical values from alpha, treat those as separate search intents and landings rather than overloading this z-test page. Introductory statistics courses constantly assign z-tests for a mean when sigma is given in the problem statement, empirical-rule drills, and comparisons of a class average against a published benchmark; a single trusted oracle that returns cleaned JSON speeds grading and demo setup. Because this capability is a pure parse engine, failed validation does not consume prepaid balance and a successful call costs the published $0.002 base price with no model tokens and no outbound network. Keep n as a whole number, keep sigma strictly positive, and pin the rounded z and p_value in tests so homework keys, LMS plugins, and edge workers stay reproducible.
Technical questions
Is the p-value one-tailed or two-tailed?
Two-tailed by default (tails=two): p = 2(1 − Φ(|z|)). Set tails=left for H1: μ < μ0 or tails=right for H1: μ > μ0.