molecalculator

Moles & Molar Mass

How to Calculate Z-Test: Formula & Steps

Calculator No. 01-8035 · Updated · Formula and assumptions shown below

The calculator on this page is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

For study and lab planning. The result follows from the numbers you enter and the formula shown. Check it against your method before you weigh, mix or dilute anything, follow the safety data sheet and your supervisor, and do not use it for clinical, dosing or medication work.

This guide explains how to calculate a one-sample z-test, which tells you whether a sample mean differs significantly from a known population mean. You enter your sample mean, population mean, population standard deviation, and sample size, and the calculator returns the z-score and its p-value (one-tailed and two-tailed).

Formula

The z-test statistic is calculated as:

z = (x̄ − μ) / (σ / √n)

  • x̄ = sample mean (unitless in this calculator, but in practice it has the same unit as the data)
  • μ = population mean (same unit as x̄)
  • σ = population standard deviation (same unit as x̄)
  • n = sample size (number of observations, a positive integer)

The denominator, σ / √n, is the standard error of the mean. It measures how much sample means typically vary around the population mean. The z-score tells you how many standard errors your sample mean is away from the population mean. A larger absolute z-score means the sample mean is less likely to have occurred by chance.

Worked Example

Using the default values: sample mean = 105, population mean = 100, population standard deviation = 15, sample size = 30.

Step 1: Calculate the standard error: σ / √n = 15 / √30 = 15 / 5.4772 = 2.7386

Step 2: Find the difference between sample and population mean: 105 − 100 = 5

Step 3: Divide the difference by the standard error: z = 5 / 2.7386 = 1.8257

Step 4: For a one-tailed test (testing if the sample mean is greater than the population mean), the p-value is the area to the right of z = 1.8257 under the standard normal curve. Using the cumulative distribution function, this is approximately 0.0339.

Step 5: For a two-tailed test (testing if the sample mean differs from the population mean in either direction), double the one-tailed p-value: 2 × 0.0339 = 0.0678.

So with these defaults, z = 1.8257, one-tailed p ≈ 0.0339, two-tailed p ≈ 0.0678.

Assumptions

  • The population standard deviation (σ) is known. If you only have a sample standard deviation, use a t-test instead.
  • The data are normally distributed, or the sample size is large enough (typically n ≥ 30) for the Central Limit Theorem to apply.
  • The observations are independent of each other.
  • The sample is randomly drawn from the population.

When to Use the Z-Test

Use a one-sample z-test when you have a single sample and you know the population standard deviation. This is common in standardized testing, quality control, and manufacturing, where the population spread is already established. If you do not know σ and have to estimate it from the sample, use a t-test instead. The z-test is also used for proportions, but the formula differs (z = (p̂ − p₀) / √(p₀(1−p₀)/n)).

How to Read the Result

First, decide your significance level (α), commonly 0.05. If the p-value is less than α, you reject the null hypothesis (which states that the sample mean equals the population mean). If the p-value is greater than α, you fail to reject the null hypothesis. For a two-tailed test, the p-value accounts for deviations in both directions; for a one-tailed test, it only considers one direction. Always choose your test direction before collecting data.

Common Mistakes

  • Using the sample standard deviation instead of the population standard deviation. This inflates or deflates the z-score and can lead to wrong conclusions.
  • Forgetting to divide by the square root of the sample size. The standard error is not σ, it is σ/√n.
  • Confusing one-tailed and two-tailed p-values. A two-tailed p-value is roughly double the one-tailed p-value for the same z-score.
  • Using a z-test when the population standard deviation is unknown and the sample is small (n < 30) and not normally distributed.
  • Mixing up the order of subtraction. The z-score is (sample mean − population mean), not the reverse. Swapping them changes the sign, which matters for one-tailed tests.

Tips

  • Check that your sample size is at least 30 if the population is not known to be normal. For smaller samples, verify normality with a histogram or a normality test.
  • Report the z-score and the p-value together, along with the sample size and the direction of the test.
  • Use the two-tailed p-value unless you have a strong prior reason to test only one direction.
  • Remember that statistical significance does not mean practical importance. A very large sample can make a tiny difference significant.
  • Keep consistent units. If your data are in grams, all means and standard deviations must be in grams.

Troubleshooting

If your z-score seems too large or too small, check the units of the standard deviation. A common error is entering the variance instead of the standard deviation. Also verify that the sample size is the number of observations, not the number of groups. If your p-value comes out as 0 or 1, your z-score is likely beyond the range of the normal table (|z| > 6), which usually indicates an input error or an extremely large effect. If the calculator shows “Cannot compute”, check that the sample size is at least 2 and the standard deviation is positive.

Frequently Asked Questions

What is the difference between a z-test and a t-test?

A z-test requires a known population standard deviation and works well with large samples. A t-test is used when the population standard deviation is unknown and must be estimated from the sample. For large samples (n ≥ 30), the two give very similar results.

Can I use a z-test for proportions?

Yes, but the formula is different. For a proportion, z = (p̂ − p₀) / √(p₀(1−p₀)/n), where p̂ is the sample proportion and p₀ is the hypothesized population proportion. This calculator is for a sample mean only.

What does a negative z-score mean?

A negative z-score means the sample mean is below the population mean. For a one-tailed test, you must check whether your hypothesis predicts a decrease; if so, the negative z-score is expected. For a two-tailed test, only the absolute value matters.

Is the z-test valid for small sample sizes?

Only if the population is known to be normally distributed. If you have a small sample (n < 30) and do not know the population distribution, the z-test may be unreliable. In that case, use a t-test, which is more robust.

What is the standard error in simple terms?

The standard error (σ/√n) is the typical amount that a sample mean deviates from the true population mean. As the sample size grows, the standard error shrinks, making the z-score larger for the same observed difference.

How do I decide between one-tailed and two-tailed?

Use a two-tailed test when you want to detect any difference, whether the sample mean is higher or lower than the population mean. Use a one-tailed test only when you have a specific directional hypothesis (e.g., the new method increases scores) and you are not interested in the opposite direction.

Related

Formula used
in m | Sample mean | - | 105 | 0
in mu | Population mean | - | 100 | 0
in sigma | Population standard deviation | - | 15 | 0.001
in n | Sample size | - | 30 | 2
out z | Z-score | - | (m - mu) / (sigma / sqrt(n)) | 4
out p1 | One-tailed p-value | - | 1 - 0.5 * (1 + erf(z / sqrt(2))) | 4
out p2 | Two-tailed p-value | - | 2 * (1 - 0.5 * (1 + erf(abs(z) / sqrt(2)))) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation with the constants and conversion factors written on the page, rounded as each result states. See method and constants, the disclaimer or report an error.

More in this section

The whole Moles & Molar Mass section →