When do you use a t-test versus a z-test?
Use a z-test when the population standard deviation is known and the sample is large (n >= 30, by convention); use a t-test when the standard deviation must be estimated from the sample, which is almost always the case in practice. For large n the two tests converge, but the t-test is the safe default.
How to think about it
Both tests compare a sample mean against a reference value or against another sample mean. The choice hinges on one question: do you know the true population standard deviation?
z-test
The z-statistic is (x_bar - mu0) / (sigma / sqrt(n)) where sigma is the known population standard deviation. The test statistic follows a standard normal distribution exactly (assuming normality or large n by the Central Limit Theorem).
When it applies:
- Population sigma is known (rare in practice — maybe a manufacturing process with decades of historical data).
- Large sample sizes where the estimated s is essentially equal to sigma.
- Proportions tests:
z = (p_hat - p0) / sqrt(p0*(1-p0)/n).
t-test
The t-statistic is (x_bar - mu0) / (s / sqrt(n)) where s is the sample standard deviation. Because s is itself a random variable, the statistic follows a t-distribution with n - 1 degrees of freedom — heavier tails than the normal to account for the additional uncertainty.
As n grows, t(n-1) converges to N(0,1), so for n >= 30 the practical difference is negligible.
Variants of the t-test
| Variant | Use case |
|---|---|
| One-sample | Compare sample mean to a known value |
| Two-sample (independent) | Compare means of two unrelated groups |
| Paired | Compare means of matched pairs (same subjects pre/post) |
Key assumptions for both
- Observations are independent.
- Data (or sampling distribution of the mean) is approximately normal — for small n this matters; for large n the CLT covers it.
- For the two-sample t-test: equal or unequal variance versions (Welch’s t-test is the robust default).