Z-Test vs T-Test
Maths: Statistics for machine learning
2 min read
Published Oct 22 2025, updated Oct 23 2025
Guide Sections
Guide Comments
Both Z-tests and T-tests are statistical hypothesis tests used to determine whether there’s a significant difference between sample data and a known or assumed population parameter.
In simple terms:
“Both tests check if your sample mean is far enough from what you expect —
the Z-test uses the population standard deviation, while the T-test uses the sample standard deviation.”
The Z-Test
When to Use:
- The population standard deviation (σ) is known
- The sample size is large (n ≥ 30)
- The data are normally distributed (or approximately normal via CLT)
Example:
“Is the average test score of 50 students different from the known population mean of 75 (σ = 10)?”
Use Z-test because σ is known and sample is large.
The T-Test
When to Use:
- The population standard deviation (σ) is unknown
- You have to estimate σ using the sample standard deviation (s)
- The sample size is small (n < 30)
- Data are approximately normally distributed
The t-distribution has heavier tails than the normal distribution, accounting for extra uncertainty from estimating σ.
Distribution Used
Test | Distribution | Description |
Z-test | Standard Normal (Z) | Bell-shaped, fixed shape |
T-test | Student’s t | Similar to normal, but heavier tails; shape changes with sample size (degrees of freedom) |
As n increases, the t-distribution approaches the normal distribution, meaning the T-test ≈ Z-test for large samples.
Typical Use Cases
Scenario | Use | Why |
Population σ is known | Z-test | We can use exact population variability |
Population σ is unknown | T-test | Must estimate variability from sample |
Small sample (n < 30) | T-test | Accounts for higher uncertainty |
Large sample (n ≥ 30) | Z-test (or T-test, both valid) | CLT ensures normal approximation |
Comparing two means | Two-sample T-test | Usually σ unknown |
Paired data (before/after) | Paired T-test | Works on differences |
Comparing proportions | Z-test | Uses population or large sample proportions |
Example in Python
Example: Compare Sample Mean to Population Mean
Both give similar results when n is large, but the T-test is more robust when σ is unknown.














