The z-test's one strict requirement
The one-sample z-test compares a sample mean with a hypothesised μ₀, exactly like the t-test, with one difference that decides everything: it demands the population standard deviation σ, known, not estimated from your sample. That knowledge removes the extra uncertainty the t distribution exists to model, so the statistic is read on the normal curve instead.
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. Reject at 0.05, but only just. 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.
When σ is 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.
Plugging 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 are too small. If σ came from the same data you are testing, use the t-test.
Frequently asked questions
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 σ completely; t prices in the uncertainty of estimating s. Both are correct, given their own assumptions.
How large must n be before z is fine with an estimated SD?
There is no bright line; the t and z answers converge as n grows and are nearly identical by n ≈ 100. Below that, t is the honest choice.