The Z-Test › The Z-Test Formula: A Deep Dive
Machine Learning from ScratchAll chapters The Z-Test › The Z-Test Formula: A Deep DiveOne section · Sections in this chapter3 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The Core Formula
The z-test statistic is:
This formula looks simple, but each component has deep meaning. Let's understand why this particular combination of quantities gives us exactly what we need for hypothesis testing.
Step 1: The Numerator Measures the Discrepancy
This is the difference between what you observed (sample mean ) and what the null hypothesis claims (population mean ).
Example: If the null hypothesis claims the population mean is 100 and you observe a sample mean of 95, the numerator is .
A difference of 5 could be huge or trivial depending on context. If you're measuring heights in millimeters, 5 mm is negligible. If you're measuring earthquake magnitudes, 5 points is catastrophic. We need to standardize.
Step 2: The Denominator Provides Context
This is the standard error, and it answers: "How much do sample means typically vary from sample to sample?"
The standard error depends on two factors:
Factor 1: Population variability (σ)
More variable populations produce more variable sample means. If individual observations vary a lot, the averages of groups of observations will also vary.
Factor 2: Sample size (n)
Larger samples produce more stable estimates. The in the denominator reflects a fundamental principle: averaging reduces noise. When you average n independent observations, random fluctuations tend to cancel out.


Step 3: The Ratio Gives Standardized Evidence
When you divide the observed discrepancy by the standard error:
You get a standardized score that tells you: "How many standard errors away from the null hypothesis is my observation?"
- means your sample mean is 1 standard error away from
- means your sample mean is 2 standard errors away
- means your sample mean is 1.5 standard errors below
The beauty of standardization is that it puts all tests on the same scale. Whether you're measuring heights, weights, temperatures, or dollars, a z-score of 2 always has the same interpretation: your observation is 2 standard errors from what the null predicts.
Why the Standard Normal Distribution?
Under the null hypothesis , if either:
- The population is normally distributed, OR
- The sample size is large enough for the Central Limit Theorem to apply
Then the z-statistic follows a standard normal distribution .
This is the key insight that makes z-tests work. We know everything about the standard normal distribution. We can calculate exact probabilities for any z-value. So once we compute z, we can immediately determine how surprising our result is under the null hypothesis.
