Four z-tests, one question each
A bakery owner keeps a notebook by the till. Eight days of cake sales: 42, 38, 45, 51, 44, 39, 47, 50. The average is 44.5, and she believes the true daily figure is 40. Is 44.5 a real lift, or just a lucky week? She has one advantage most students do not: years of till records pin the daily spread at σ = 6, documented, not guessed. That single fact is what makes her question a z-test.
The z-test compares a sample result with a claim, and reads the gap on the normal curve. It works for means and for rates. The price of admission is a known population standard deviation, or a known claimed rate. Pay it, and the arithmetic is the lightest of all the hypothesis tests. Skip it, and the t-test is the honest tool.
| Your data | The test | What it asks |
|---|---|---|
| One group, one claimed value, σ known | One-sample | Is this mean different from μ₀? |
| Two separate groups, both σ known | Two-sample | Do these two means differ? |
| One group, x successes in n trials | One proportion | Is this rate different from p₀? |
| Two groups, two rates | Two proportions | Do these two rates differ? |
That is the whole decision. Count the groups. Then ask whether you are testing a mean or a rate. A shop's return rate is a proportion. Two production lines with documented sigmas are a two-sample z. The bakery's eight days are one-sample. Pick from the design, before you see any output. The design tells you which one fits; the p-value never does.
The four worked examples, side by side
The bakery data (mean 44.5, n = 8) against μ₀ = 40, with a genuinely known σ = 6 from years of records: z = 4.5 ÷ (6 ÷ √8) = 2.1213, two-tailed p = 0.0339. The 95% interval for the mean (40.34 to 48.66) clears 40 entirely. Compare the t-test on the same numbers (p = 0.0316, because its estimated s happened to come out below 6): the tests answer the same question with different information, and their p-values are not obliged to match. The dedicated one-sample z-test calculator runs this same test with full steps and the interval.
Two production lines, five measured parts each: means 84.6 and 75.6, with long-documented σ = 5 and σ = 4. The standard error of the difference is √(25/5 + 16/5) = 2.864; z = 9 ÷ 2.864 = 3.1429, two-tailed p = 0.0017. The lines' true means differ. The 95% interval for the gap (3.39 to 14.61) excludes zero by a wide margin.
A shop believes half its customers come back. Of 120 tracked customers, 64 returned: p̂ = 0.5333. z = (0.5333 − 0.5) ÷ √(0.25 ÷ 120) = 0.7303, two-tailed p = 0.4652. Nowhere near significance. A 53% return rate in 120 customers is exactly the kind of wobble a true 50% produces. The 95% interval for the proportion (0.444 to 0.623) contains 0.5 comfortably and says the same thing with more information.
A new checkout flow converts 64 of 120 visitors against the old one's 48 of 110. p̂₁ = 0.5333, p̂₂ = 0.4364, pooled p = 0.4870. z = 1.4697, two-tailed p = 0.1416. A 9.7-point gap in the samples, but with these sample sizes, gaps that large arise by chance about one time in seven when nothing differs. The 95% interval for the difference (−0.032 to 0.226) contains zero and reaches from slightly negative to a hefty +23 points: the honest summary is "unresolved: get more data", not "no effect".
Reading the output, in order
Start with the interval, not the p-value. It says how big the difference plausibly is, in the units you care about: cakes a day, parts per line, percentage points of conversion. Then the p-value: how surprising the data would be if the null were true. Then the z statistic itself: the observed gap measured in standard errors, so a z of 2 means two standard errors from the claim, and a z of 3 means three. Report all three and the reader never has to guess what you found.
The one rule that decides z or t
Ask where your σ came from. A calibrated instrument, a standardised test's design, or years of documented process records: z is earned. The same dataset you are testing: t is the honest choice, because estimating the spread adds uncertainty the normal curve does not price in. With very large samples the two answers converge and the choice stops mattering. Below that, the difference is real, and it is biggest exactly where samples are small.
Pasting the sample SD into the σ box on a small sample. That is not a z-test; it is a t-test wearing a costume, and its p-values come out too small. The same trap applies to proportions: the one-proportion test's standard error is built from the claimed p₀, not from the sample rate, because the test asks how surprising the data would be if the claim were true.
Frequently asked questions
Which z-test do I need?
Count the groups, then check means or rates. One group against a claimed mean with a known sigma: one-sample. Two groups, both sigmas known: two-sample. One group, x successes in n trials against a claimed rate: one proportion. Two groups, two rates: two proportions.
When is sigma honestly known?
A measurement process calibrated for years, with a stable, documented spread. Standardised testing, where the population SD is set by the test's design. Very large samples, where s is so precise that z and t agree to several decimals anyway.
Why does the z-test give a different p from the t-test on the same data?
Because they use different denominators and different curves. z trusts the supplied sigma completely; t prices in the uncertainty of estimating s. Both are correct, given their own assumptions.
One-tailed or two-tailed?
Two-tailed is the default: it catches a difference in either direction. Use one-tailed only when the direction was fixed before the data arrived, for example a test that can only improve a process. Switching tails after seeing the result is test shopping.