Parameters
Enter your data to get the test statistic (z or t), p-value and test decision.
Reference value you want to test the sample against: the one that appears in \(H_0: \mu = \mu_0\).
The mean you have calculated from your observed data.
A measure of spread for your data: the population standard deviation σ if you know it (z test), or the sample standard deviation s if you estimate it from the sample (t test). Pick which one in the "Type of standard deviation" field.
Number of observations in your sample.
Use z if you know the population standard deviation σ; use t (the most common case) if you only have the sample standard deviation s calculated from your data.
The two-tailed test detects that μ differs from μ₀ in either direction. The one-tailed options only detect one specific direction (μ greater or smaller); use them only if you know the expected direction in advance.
Probability of wrongly rejecting \(H_0\) when it is actually true. Many analyses use 0.05; in critical contexts 0.01 may be preferred.
Rejection regions and observed statistic
What is a hypothesis test for a mean?
It is the procedure that lets you decide, from a sample, whether a population mean can equal a reference value \(\mu_0\) or whether the data indicate that it is different. It is also known as the one-sample t-test (or z-test, when the population standard deviation is known). It is one of the most widely used tests in quality control, biomedical research, education and business analytics: do the parts weigh 500 g on average, as the manufacturer claims? Has the mean waiting time changed? Do my students score above the national average?
The logic resembles a trial. You start from a null hypothesis \(H_0\) ("the mean is \(\mu_0\)"), which stands as long as there is no evidence against it, just like the presumption of innocence. Then you look at how far the sample mean \(\bar{x}\) is from \(\mu_0\) and ask: if \(H_0\) were true, would a difference like this be unusual by chance alone? If it would be very unusual, \(H_0\) is rejected in favour of the alternative hypothesis \(H_1\); if not, the data are compatible with \(H_0\) and it is not rejected.
There are two scenarios. If you know the population standard deviation \(\sigma\), you use the z-test; if \(\sigma\) is unknown and is estimated with the sample standard deviation \(s\) — the usual case in practice — you use Student's t-test, which accounts for the extra uncertainty of estimating variability from the sample itself.
Hypotheses and test statistic
\(H_0: \mu = \mu_0\)
\(H_1: \mu \neq \mu_0\), \(\mu > \mu_0\) or \(\mu < \mu_0\)
If \(\sigma\) is known: \( z = \frac{\bar{x} - \mu_0}{\sigma / \sqrt{n}} \)
If \(\sigma\) is unknown: \( t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}} \), with \(df=n-1\)
- \(\bar{x}\): sample mean.
- \(\mu_0\): mean stated in the null hypothesis.
- \(\sigma\): population standard deviation (if known).
- \(s\): sample standard deviation (if \(\sigma\) is unknown).
- \(n\): sample size.
The denominator, \(\sigma/\sqrt{n}\) or \(s/\sqrt{n}\), is the standard error of the mean: it measures how much \(\bar{x}\) varies from one sample to another. The statistic therefore expresses how many standard errors the observed mean lies from the hypothesized value. A statistic close to 0 means the data fit \(H_0\); the larger it is in absolute value, the harder it is to attribute the difference to chance. That is why the same difference \(\bar{x}-\mu_0\) carries more weight with a large sample or with tightly clustered data.
How to run the test, step by step
- State the hypotheses before looking at the data: \(H_0: \mu = \mu_0\) and the alternative you care about (different, greater or less).
- Set the significance level \(\alpha\): the risk you accept of rejecting \(H_0\) when it is true. The usual choice is 0.05.
- Compute the z or t statistic from the mean, the standard deviation and the sample size.
- Get the p-value (or compare the statistic with the critical value from the normal or Student's t table).
- Decide and interpret in the context of the problem, and report the confidence interval and the effect size alongside the decision.
The calculator above does steps 3 and 4 for you and draws the result on the distribution.
Decision rule
- If the p-value is less than \(\alpha\), \(H_0\) is rejected.
- If the p-value is greater than or equal to \(\alpha\), there isn't enough evidence to reject \(H_0\).
- A non-significant result does not prove that \(H_0\) is true.
Deciding with the p-value or with the critical value is equivalent: the p-value is below \(\alpha\) exactly when the statistic falls in the rejection region.
Two-tailed or one-tailed test?
It depends on the question. If you want to know whether the mean is different from \(\mu_0\), in either direction, the test is two-tailed. If only one direction matters — greater, or less — it is one-tailed.
| Type | Alternative hypothesis | \(H_0\) is rejected if… | p-value |
|---|---|---|---|
| Two-tailed | \(H_1: \mu \neq \mu_0\) | the statistic is very large or very small | both tails: \(2\,P(T \geq |t|)\) |
| Right-tailed | \(H_1: \mu > \mu_0\) | the statistic is very large | the right tail: \(P(T \geq t)\) |
| Left-tailed | \(H_1: \mu < \mu_0\) | the statistic is very small (negative) | the left tail: \(P(T \leq t)\) |
A one-tailed test puts all of \(\alpha\) on one side, so it detects a difference in that direction more easily; in exchange, it cannot detect a difference in the opposite direction. When the statistic falls in the expected direction, its p-value is half the two-tailed one.
The direction must be chosen before seeing the data and for a reason grounded in the problem (for example, "I only care whether the mean weight is below the stated one"). Choosing the tail after seeing which way the data point effectively doubles the false-positive risk. When in doubt, use the two-tailed test.
z-test or t-test?
z-test: used when the population \(\sigma\) is known, which is uncommon; it happens, for example, with industrial processes that have a long track record or with standardized tests designed with a fixed standard deviation. The statistic follows a standard normal distribution under \(H_0\).
t-test: used when \(\sigma\) is unknown and is replaced by \(s\). Because \(s\) is only an estimate and changes from sample to sample, the statistic is more variable than a normal: it follows Student's t distribution with \(n-1\) degrees of freedom, which has heavier tails. This makes the critical value larger and demands somewhat more evidence to reject \(H_0\), especially with small samples.
| Sample size | Critical t value (two-tailed, \(\alpha = 0.05\)) |
|---|---|
| \(n = 5\) | 2.776 |
| \(n = 10\) | 2.262 |
| \(n = 30\) | 2.045 |
| \(n = 100\) | 1.984 |
| Normal (z) | 1.960 |
As \(n\) grows, the t distribution gets closer and closer to the normal, which is why both methods converge for large samples. Even so, if you estimated the standard deviation from the sample, the right choice is always t, whatever the sample size: using z with \(s\) in a small sample produces more false positives than \(\alpha\) indicates. The well-known "\(n \geq 30\)" rule is about something else: when non-normal data stop being a concern (see the assumptions).
What the p-value is (and what it is not)
The p-value is the probability of obtaining a result as far from \(\mu_0\) as the one observed, or farther, assuming that \(H_0\) is true. It measures how surprising your data would be if the mean really were \(\mu_0\): the smaller it is, the worse the data fit the null hypothesis.
For example, a p-value of 0.073 means that, if the mean really were \(\mu_0\), about 7 in every 100 samples of the same size would give a mean as far off as yours, or farther. That is not exceptional, which is why \(H_0\) is not rejected at \(\alpha = 0.05\).
The p-value is not:
- The probability that \(H_0\) is true. With \(p = 0.03\) there is no "3% chance that the mean is \(\mu_0\)".
- The probability that the result "is due to chance".
- A measure of the size or importance of the difference: a tiny difference can give a very small p-value if the sample is huge.
Nor should it be confused with \(\alpha\). The significance level is set before collecting the data and is the decision threshold; the p-value is computed afterwards, from the data. Report the exact p-value (\(p = 0.073\)) rather than just "significant" or "not significant".
Assumptions of the test
- A random sample from the population you want to draw conclusions about.
- Independent observations: the value of one does not affect another. This fails with repeated measurements on the same individuals or with data clustered in batches or families.
- A quantitative variable (weight, time, score…). For percentages or yes/no data, use the test for one proportion.
- Normality: the variable is approximately normally distributed, or the sample is large enough for the sample mean to be approximately normal by the central limit theorem. As a guide, \(n \geq 30\) is usually enough unless the distribution is strongly skewed.
With small samples, normality matters more. You can check it with a histogram or with the Shapiro-Wilk test, and you should look for outliers, because a single extreme value can drag the mean and inflate the standard deviation. If the data are clearly skewed and the sample is small, a non-parametric test such as the Wilcoxon signed-rank test is preferable.
If you have two measurements on the same individual (before and after), the right test is the one for paired means; if you are comparing two different groups, the one for two independent means.
Worked example 1: two-tailed t-test
A factory claims that its machine produces parts with an average weight of \(\mu_0 = 500\) g. To verify this, an inspector takes a sample of \(n = 25\) parts and obtains \(\bar{x} = 497\) g and sample standard deviation \(s = 8\) g. The goal is to test whether the mean weight differs significantly from 500 g with \(\alpha = 0.05\) (two-tailed).
The hypotheses are \(H_0\colon \mu = 500\) versus \(H_1\colon \mu \neq 500\). Since \(\sigma\) is unknown, the Student's t statistic is used with \(df = n - 1 = 24\) degrees of freedom:
\( t = \dfrac{\bar{x} - \mu_0}{s/\sqrt{n}} = \dfrac{497 - 500}{8/\sqrt{25}} = \dfrac{-3}{1.6} = -1.875 \)
For a two-tailed test with \(\alpha = 0.05\) and 24 degrees of freedom, the critical value is \(t_{0.025,\,24} \approx 2.064\). Since \(|t| = 1.875 < 2.064\), the statistic does not fall in the rejection region.
The p-value associated with the two-tailed test is \(p \approx 0.073\). Since \(p = 0.073 > \alpha = 0.05\), \(H_0\) is not rejected.
Conclusion: with the available data there is not enough evidence to claim that the mean weight departs from 500 g at the 5% significance level. The machine may be correctly calibrated.
What else to look at. The 95% confidence interval for the mean is \(497 \pm 2.064 \times 1.6\), that is, from 493.70 to 500.30 g: it contains 500, consistent with not rejecting \(H_0\), but also values such as 494 g. So the result does not prove that the machine is well calibrated. In fact, with only 25 parts, the probability of detecting a real 3 g shift (the power) is about 44%; reaching 80% would take about 56 parts, as you can check with the sample size calculator for a one-mean test.
In the calculator: μ₀ = 500, x̄ = 497, deviation = 8, n = 25, "I only know the sample s (t-test)" and "Two-tailed (≠)".
Worked example 2: one-tailed z-test
An aptitude test is designed so that scores in the general population have mean 100 and standard deviation \(\sigma = 15\). A training centre wants to know whether its students score above average. A random sample of \(n = 36\) students obtains a mean score of \(\bar{x} = 105\). The test uses \(\alpha = 0.05\).
Only one direction matters, so the test is right-tailed: \(H_0\colon \mu = 100\) versus \(H_1\colon \mu > 100\). Since \(\sigma\) is known, the z statistic is used:
\( z = \dfrac{\bar{x} - \mu_0}{\sigma/\sqrt{n}} = \dfrac{105 - 100}{15/\sqrt{36}} = \dfrac{5}{2.5} = 2.00 \)
The right-tailed critical value with \(\alpha = 0.05\) is \(z_{0.95} \approx 1.645\). Since \(z = 2.00 > 1.645\), the statistic falls in the rejection region. The p-value is \(P(Z \geq 2.00) \approx 0.0228\), below \(\alpha\): \(H_0\) is rejected.
Conclusion: there is statistical evidence that the mean score of the centre's students exceeds 100. The observed difference is 5 points, a third of a standard deviation (\(d = 5/15 \approx 0.33\)): a real effect, but small to moderate in size. With a two-tailed test, the p-value would have been twice as large, 0.0455.
In the calculator: μ₀ = 100, x̄ = 105, deviation = 15, n = 36, "I know the population σ (z-test)" and "Right-tailed (>)".
How to interpret the result
Rejecting \(H_0\) (p-value < α) means that, if the population mean were really \(\mu_0\), it would be very unlikely to have observed a sample value as far off as the one obtained. It is concluded that there is statistical evidence that \(\mu \neq \mu_0\) (or > / <, depending on the chosen alternative). However, rejecting \(H_0\) does not mean the difference is large or important: with very large samples even a difference of a few tenths can turn out to be significant.
Failing to reject \(H_0\) (p-value ≥ α) does not prove that the mean equals \(\mu_0\); it only indicates that the data are compatible with that value at the chosen significance level. Low power — due to a small sample or high variance — can prevent detecting real differences. Before concluding "there is no effect," check the power of the test and the confidence interval.
Development and additional details
Regarding the z or t statistic shown by the tool: its magnitude indicates how many standard errors \(\bar{x}\) is away from \(\mu_0\). In the chart, the green zone is the non-rejection region, the red zones are the critical regions and the amber line marks the observed statistic. If the amber line falls in red, p-value < α.
The two possible errors
The decision is made from a sample, so it can be wrong in two ways:
- Type I error (false positive): rejecting \(H_0\) when it is true. Its probability is \(\alpha\), and you choose it.
- Type II error (false negative): failing to reject \(H_0\) when it is false. Its probability is called \(\beta\), and \(1-\beta\) is the power of the test.
Lowering \(\alpha\) makes it harder to reject \(H_0\) and, with the same sample, raises \(\beta\). The way to reduce both at once is to increase the sample size. You can see this trade-off in the type I and type II error simulator.
Relationship with the confidence interval
The two-tailed test and the confidence interval are two sides of the same calculation: \(H_0\) is rejected at level \(\alpha\) exactly when \(\mu_0\) lies outside the \(100(1-\alpha)\%\) confidence interval for the mean. The interval also tells you what the test does not: which values of the mean are compatible with the data, and how precisely it has been estimated. Compute it with the confidence interval for a mean (or its known-σ version).
Statistical significance and practical relevance
A statistically significant difference is not necessarily one that matters. To judge its magnitude, use the effect size; the most common one here is Cohen's d, \(d = (\bar{x}-\mu_0)/s\), which expresses the difference in standard deviations. As a rough guide, 0.2 is considered a small effect, 0.5 medium and 0.8 large, although what counts is which difference is relevant in your problem: 3 g may be irrelevant in a bag of cement and critical in a medicine.
Common mistakes
- Reading "\(H_0\) is not rejected" as "\(H_0\) is true". Absence of evidence is not evidence of absence, especially with small samples.
- Choosing a tail after seeing the data, or switching from two-tailed to one-tailed to "achieve" significance.
- Confusing significant with important. Always report the observed difference and its confidence interval.
- Using z with the sample standard deviation in small samples, instead of Student's t.
- Applying it to data that are not independent, such as before/after measurements on the same individuals.
- Repeating the test many times (with different variables or subgroups) and keeping the one that comes out significant: with \(\alpha = 0.05\), 1 in every 20 tests of true null hypotheses will be significant by chance alone.
Frequently asked questions
- When should I use z and when t? Use z if you know the population \(\sigma\); use t if \(\sigma\) is unknown and you estimate it from the sample, which is the most common case.
- Is this the same as the one-sample t-test? Yes. "Hypothesis test for a mean with unknown \(\sigma\)" and "one-sample t-test" are names for the same procedure.
- What does the p-value represent in this mean test? The probability, if \(H_0\) is true, of observing a result as extreme as the one obtained, or more. It is not the probability that \(H_0\) is true.
- What is a typical α? Many analyses use 0.05, although 0.01 may be preferred in critical contexts.
- Can I use the test with fewer than 30 observations? Yes, with Student's t, as long as the data are approximately normal and there are no marked outliers. With small samples and strongly skewed data, a non-parametric test is preferable.
- What if my data are not normal? With large samples the test remains valid thanks to the central limit theorem. With small samples, check normality with the Shapiro-Wilk test and consider a non-parametric test such as Wilcoxon's.
- Two-tailed or one-tailed? Two-tailed if any difference from \(\mu_0\) matters; one-tailed only if, before seeing the data, a single direction is all you care about. When in doubt, two-tailed.
- What sample size do I need? It depends on the difference you want to detect, the variability and the desired power. Work it out with the sample size calculator for a one-mean test.
- Should I report anything else? Yes: add a confidence interval and an effect size to interpret the practical relevance.
- What is the minimum detectable effect (MDE)? It is the smallest difference from \(\mu_0\) that your study is designed to detect with a given power (for example, 80%) and a fixed significance level \(\alpha\). If the true effect is smaller than the MDE, the test may fail to detect it due to lack of power.
References: Student's t-test and Statistical hypothesis testing — Wikipedia