When to use a z-test
A z-test compares a mean with a target value, or two means, when the population standard deviation is known. That is uncommon in practice. It applies in quality control with a long record of the process, or in standardised tests with a published SD. If you estimated the SD from your sample, use a t-test. See t-test vs z-test.
Worked example: one sample
Bottles should hold 500 ml, with a known SD of 10 ml. A sample of 49 has a mean of 503 ml. The standard error is 10 / √49 = 1.43, so z = 2.10 and p = .036. The 95% CI for the difference is 0.2 to 5.8 ml. See how to do a z-test.
Worked example: two samples
Means of 72 and 68, known SDs of 10 and 12, and sizes 50 and 60. The standard error is √(100/50 + 144/60) = 2.10, so z = 1.91 and p = .057, just short of significance at the 5% level.
For percentages, use the two-proportions calculator.
Frequently asked questions
What is the formula for a z-test?
z = (sample mean - hypothesised mean) / (sigma / square root of n).
When should I use z instead of t?
When the population SD is genuinely known. With an SD estimated from the sample, use t, whatever the sample size.
Can I use a z-test with a large sample?
With large samples, t and z give nearly the same answer, so it makes little difference. Software usually reports t anyway.