Z-Test for a Mean Calculator
Test whether a population mean differs from a hypothesized value when the population standard deviation is known. Enter the sample mean, hypothesized mean, σ, sample size and significance level to get the z statistic, p-value and decision.
Test a Population Mean When the Standard Deviation Is Known
Z-Test for a Mean Formula
Where:
- \(\bar{x}\) — sample mean
- \(\mu_0\) — hypothesized population mean stated by the null hypothesis \(H_0\)
- \(\sigma\) — known population standard deviation
- \(n\) — sample size
The statistic measures how many standard errors the sample mean lies from the hypothesized value. Under \(H_0\), \(z\) follows the standard normal distribution, so the p-value is computed from \(\Phi\), the standard normal CDF:
\[ p = 2\left(1 - \Phi(|z|)\right) \quad \text{(two-sided)}, \qquad p = \Phi(z) \quad \text{(left-sided)}, \qquad p = 1 - \Phi(z) \quad \text{(right-sided)} \]
Z-Test for a Mean – Calculation Example
Example: a machine is specified to fill bottles with a mean of 100 ml. The process standard deviation is known to be 15 ml. A random sample of 36 bottles has a mean of 105 ml. Is the true mean different from 100 ml at the 5% significance level (two-sided test)?
\[ SE = \frac{\sigma}{\sqrt{n}} = \frac{15}{\sqrt{36}} = \frac{15}{6} = 2.5 \]
\[ z = \frac{\bar{x} - \mu_0}{SE} = \frac{105 - 100}{2.5} = 2 \]
\[ p = 2\left(1 - \Phi(2)\right) = 2(1 - 0.9772) = 0.0455 \]
Result: \(z = 2\), \(p = 0.0455\), critical value \(\pm 1.96\). Since \(p \le 0.05\) (equivalently, \(|z| = 2 \ge 1.96\)), reject \(H_0\): the data provide statistically significant evidence that the true mean differs from 100 ml.
How to Use the Calculator
- Enter the Sample mean \(\bar{x}\) computed from your data.
- Enter the Hypothesized mean \(\mu_0\) — the value of the population mean claimed by the null hypothesis.
- Enter the Population standard deviation \(\sigma\). This must be the known population value, not the sample standard deviation \(s\).
- Enter the Sample size \(n\), the number of observations.
- Choose the Alternative hypothesis: two-sided (\(\mu \ne \mu_0\)), left-sided (\(\mu \mu_0\)).
- Select the Significance level \(\alpha\) (commonly 0.05).
- Read the Z-test statistic, the p-value, the critical value and the decision (reject or fail to reject \(H_0\)) in the results panel.
What Is a Z-Test for a Mean?
A one-sample z-test answers the question: is the average of a population equal to a specific value, given what I observed in a sample? You start with a null hypothesis \(H_0: \mu = \mu_0\) and compare it with an alternative claim \(H_1\). The test converts the distance between your sample mean and the hypothesized mean into a z statistic expressed in standard errors, which places your result on the familiar standard normal curve.
The distinguishing feature of the z-test is that it requires the population standard deviation \(\sigma\) to be known in advance — from historical process data, a calibrated instrument or a well-established reference value. When \(\sigma\) is known, the sampling distribution of the mean is exactly normal (if the population is normal) or approximately normal for large samples by the central limit theorem, so no extra uncertainty from estimating the spread needs to be accounted for.
The output is interpreted through the p-value: the probability of observing a sample mean at least as extreme as yours if \(H_0\) were true. A small p-value means the data would be surprising under the null hypothesis, so you reject it. Equivalently, you can compare the z statistic with the critical value: for a two-sided test at \(\alpha = 0.05\), the critical values are \(\pm 1.96\), so any \(|z|\) beyond that leads to rejection. Both approaches always give the same decision.
When you reject \(H_0\), the same ingredients build a confidence interval: \(\bar{x} \pm 1.96 \cdot \sigma/\sqrt{n}\) is the two-sided 95% confidence interval for \(\mu\). A significant two-sided test at level \(\alpha\) corresponds exactly to a \((1-\alpha)\times 100\%\) confidence interval that does not contain \(\mu_0\).
Assumptions, Limitations and Practical Tips
- Known σ is essential. If the standard deviation must be estimated from the sample, use a one-sample t-test instead — the t distribution is wider and produces more conservative (larger) p-values, especially for small samples. For comparing two proportions instead of means, see the two-proportion z-test calculator.
- Random, independent observations. The sample should be drawn randomly, and observations must not influence each other. Violations (e.g. repeated measurements of the same subjects) invalidate the p-value.
- Normality. With \(n \ge 30\), the central limit theorem makes the normal approximation comfortable for most data shapes. With fewer than 30 observations, only use the z-test if the population itself can reasonably be treated as normal; otherwise consider a nonparametric alternative such as the Wilcoxon signed-rank test.
- One-sided vs. two-sided. Choose the alternative hypothesis based on the research question before looking at the data. A one-sided test is more powerful in its chosen direction but cannot detect effects in the opposite direction.
- Significance is not importance. With a large enough sample, even a trivially small difference from \(\mu_0\) becomes statistically significant. Always pair the test with an effect size — the Cohen's d calculator quantifies how large the difference actually is — and report the confidence interval.
- Multiple testing. Running many z-tests on the same dataset inflates the chance of a false positive; the significance level applies to each test individually, not to the whole family of tests.
Frequently Asked Questions
How do I calculate a z-test for a mean by hand (without a calculator)?
Compute the standard error first: \(SE = \sigma/\sqrt{n}\). Then find the test statistic \(z = (\bar{x} - \mu_0)/SE\). For the p-value, look up the cumulative probability \(\Phi(z)\) in a standard normal table: a two-sided p-value is \(2(1-\Phi(|z|))\). Finally, compare the p-value with your chosen \(\alpha\): if \(p \le \alpha\), reject \(H_0\). You can also compare \(z\) directly with the critical value, e.g. \(\pm 1.96\) for a two-sided test at \(\alpha = 0.05\).
When should I use a z-test instead of a t-test?
Use the z-test only when the population standard deviation \(\sigma\) is genuinely known in advance — for example, from long historical process data or an instrument specification. If you had to estimate the spread from the sample itself, that number is the sample standard deviation \(s\), and the correct procedure is a one-sample t-test. Using \(s\) in the z-test formula understates the uncertainty and produces p-values that are too small, especially with fewer than 30 observations.
What z value is considered statistically significant?
It depends on the alternative hypothesis and \(\alpha\). For a two-sided test at \(\alpha = 0.05\), the threshold is \(|z| \ge 1.96\); at \(\alpha = 0.01\) it is \(|z| \ge 2.576\); at \(\alpha = 0.10\) it is \(|z| \ge 1.645\). A handy rule: \(|z| \ge 2\) is roughly the 5% significance boundary (\(p \approx 0.0455\)), and \(|z| \ge 3\) is highly significant (\(p \approx 0.0027\)). Note that a significant z does not mean the difference is practically important.
What is the difference between a one-sided and a two-sided z-test?
A two-sided test checks whether the mean differs from \(\mu_0\) in either direction, so the \(\alpha\) is split between the two tails (critical value 1.96 at 5%). A one-sided test only detects departures in the direction you specified beforehand — e.g. \(\mu > \mu_0\) uses the single upper tail (critical value 1.645 at 5%), making it easier to reach significance. Decide the direction from your research question before collecting data; switching after seeing the results inflates the false-positive rate.
What are the most common mistakes when performing a z-test?
The biggest one is entering the sample standard deviation \(s\) instead of the known population \(\sigma\) — that turns the problem into a t-test and biases the p-value downward. Other frequent errors: choosing the one-sided alternative after looking at the data, using a non-random or non-independent sample (which invalidates the p-value entirely), ignoring whether \(n\) is large enough when the data are skewed, and interpreting p > α as proof that \(H_0\) is true — it only means the data are compatible with it.
What sample size do I need for the z-test to be valid?
There is no strict minimum, but validity depends on the population's shape. With \(n \ge 30\), the central limit theorem makes the sampling distribution of the mean approximately normal for almost any population, so the z-test is safe. With \(n < 30\), the population itself should be reasonably normal — otherwise consider the Wilcoxon signed-rank test. If \(\sigma\) is unknown (the usual small-sample situation), the t-test is typically the appropriate choice regardless of normality concerns.
Can a z-test be significant when the actual difference is tiny?
Yes. The z statistic grows with \(\sqrt{n}\), so with a large enough sample even a negligible difference from \(\mu_0\) yields a small p-value. For example, a difference of 0.1 with \(SE = 0.05\) gives \(z = 2\), "significant" at 5%, even though the effect is trivial. Always report an effect size (such as \((\bar{x} - \mu_0)/\sigma\), Cohen's d) and a confidence interval alongside the p-value to show whether the difference matters in practice.