The Core Difference in One Sentence
A z-test uses the known population standard deviation (σ) and the standard normal distribution. A t-test estimates standard deviation from the sample (s) and uses the t-distribution, which has heavier tails to account for that uncertainty. Both test whether a sample mean differs significantly from a hypothesized value, but the t-test is correct for the vast majority of real research because σ is almost never known.
Think of it this way. Suppose you want to know whether a factory's output weighs what the label says. If you have years of historical records giving you the exact population-level variability, you can use a z-test. But in a new study — a clinical trial, a survey, a classroom experiment — you only have the data in front of you, so you estimate the variability from your sample. That estimation introduces an extra layer of uncertainty, and the t-distribution is the mathematical tool built to handle it.
The two tests share the same logic and nearly the same formula. The critical difference is in the denominator (which standard deviation you use) and the distribution you compare against to get a p-value.
What Each Test Is
The T-Test
The t-test was developed by William Sealy Gosset, writing under the pseudonym "Student" at the Guinness brewery in 1908. He needed a method for drawing conclusions from small batches of barley and hops where population parameters were never known in advance. The resulting test — still called Student's t-test — remains one of the most widely used procedures in statistics.
What makes the t-distribution different from the normal distribution is its shape. Because you're estimating σ from your data, there's more variability in your estimate when sample sizes are small. The t-distribution accounts for this by having heavier tails — it assigns more probability to extreme values than the normal distribution does. As your sample size grows, this extra uncertainty shrinks, and the t-distribution gradually converges to the normal distribution.
The Z-Test
The z-test relies on the central limit theorem: regardless of the population's original distribution, the distribution of sample means becomes approximately normal as n grows. When n is large (typically n ≥ 30 is the rule of thumb), the sample standard deviation s is a reliable estimate of σ, and the distinction between the two tests narrows significantly.
Z-tests are also used for comparing proportions — for example, whether the fraction of customers who click a button differs between two website designs. The z-test calculator handles both mean and proportion tests.
Formulas Side by Side
The structure of both test statistics is identical: subtract the null hypothesis mean from the sample mean, then divide by the standard error. The only difference is which standard deviation goes into the standard error calculation.
x̄ = sample mean
μ₀ = hypothesized mean (H₀)
s = sample standard deviation
n = sample size
df = n − 1 (degrees of freedom)
x̄ = sample mean
μ₀ = hypothesized mean (H₀)
σ = known population standard deviation
n = sample size
Compare to z-table (no df needed)
After computing the test statistic, the comparison step differs. For a t-test, you look up the p-value using the t-distribution with n − 1 degrees of freedom. For a z-test, you look up the p-value using the standard normal distribution (the z-table). Common critical values for reference:
| Significance Level (α) | Test Type | Z Critical Value | T Critical Value (df = 10) | T Critical Value (df = 30) |
|---|---|---|---|---|
| 0.05 | Two-tailed | ±1.960 | ±2.228 | ±2.042 |
| 0.05 | One-tailed | ±1.645 | ±1.812 | ±1.697 |
| 0.01 | Two-tailed | ±2.576 | ±3.169 | ±2.750 |
| 0.01 | One-tailed | ±2.326 | ±2.764 | ±2.457 |
| 0.10 | Two-tailed | ±1.645 | ±1.812 | ±1.697 |
Notice that at df = 30 the t critical values are already close to z critical values. At df = 120, they are nearly identical. This is why large samples make the choice less consequential in practice.
When to Use Which Test
The decision framework is straightforward. Answer the questions in order and you will arrive at the right test every time.
Decision Tree: T-Test vs Z-Test
Many textbooks say "use z-test when n ≥ 30." This is a practical simplification. The t-test is technically always more correct when σ is unknown — even with n = 200. The reason the rule exists is that for large n, the difference in results is negligible. Most modern statisticians and software default to t-test for all mean comparisons, regardless of sample size, when σ is unknown.
Full Comparison Table
| Feature | T-Test | Z-Test |
|---|---|---|
| Standard deviation used | Sample SD (s) — estimated from data | Population SD (σ) — known in advance |
| Reference distribution | t-distribution (df = n − 1) | Standard normal distribution (z) |
| Degrees of freedom | Required (n − 1 for one-sample) | Not needed |
| Typical sample size | Any size; especially n < 30 | n ≥ 30, or σ known |
| Distribution shape | Heavier tails than normal; shape depends on df | Fixed bell curve (μ = 0, σ = 1) |
| Critical values | Higher than z-values (more conservative) | Fixed: ±1.645 (α=.05 one-tail), ±1.96 (α=.05 two-tail) |
| Formula | t = (x̄ − μ₀) / (s / √n) | z = (x̄ − μ₀) / (σ / √n) |
| Used for proportions? | No (use z-test for proportions) | Yes (when np ≥ 10 and n(1−p) ≥ 10) |
| When σ is unknown | Correct choice | Incorrect — do not substitute s for σ and use z |
| Software default | R, Python, SPSS, Excel default to t-test for means | Explicit z-test function required |
| Converges to the other? | Yes — as df → ∞, t → z | Z is the limit of t as n increases |
| Common applications | Medical trials, psychology, education, business experiments | Large surveys, quality control with known process σ, A/B testing proportions |
T-Distribution vs Normal Distribution
Understanding why the t-distribution looks the way it does explains why the two tests exist. The key is in what happens when you replace σ with s in the denominator of the test statistic.
When σ is known, the standardized statistic (x̄ − μ₀) / (σ / √n) follows a perfect standard normal distribution — a fixed bell curve centered at zero with standard deviation of 1. Its shape does not change with sample size.
When you substitute s for σ, you introduce sampling variability in the denominator. Sometimes s overestimates σ, sometimes it underestimates. This extra randomness makes the ratio more volatile — you get more extreme values than a standard normal distribution would predict. The t-distribution captures this by having fatter tails that shrink as n increases.
How Degrees of Freedom Change the Shape
Why small samples need heavier tails
| Degrees of Freedom (df) | t critical value at α = .05 (two-tailed) | Standard normal z-value | Extra coverage needed |
|---|---|---|---|
| df = 1 | 12.706 | 1.960 | +549% |
| df = 5 | 2.571 | 1.960 | +31% |
| df = 10 | 2.228 | 1.960 | +14% |
| df = 30 | 2.042 | 1.960 | +4% |
| df = 120 | 1.980 | 1.960 | +1% |
| df = ∞ | 1.960 | 1.960 | 0% (identical) |
With df = 1 (n = 2), the t critical value is over 12 — you need extreme evidence before rejecting H₀ because your estimate of σ from just two observations is unreliable. As df grows, this conservatism disappears.
The practical implication: at any given sample of data, the t-test gives a wider confidence interval and a higher p-value than a z-test using the same numbers. This is intentional — it is the t-distribution being honest about the uncertainty in s as an estimator of σ.
Assumptions of Each Test
Both tests have conditions that must hold for the results to be valid. Violating them does not necessarily make the test useless — some violations matter more than others — but knowing them helps you decide whether your data qualifies.
| Assumption | T-Test | Z-Test |
|---|---|---|
| Random sampling | Required | Required |
| Independence of observations | Required | Required |
| Population normality (or CLT) | Required for small n; CLT handles large n | Required; CLT applies for n ≥ 30 |
| Continuous numeric data | Required | Required (proportions use different z-formula) |
| σ known | No — s used instead | Yes — σ must be known, not estimated |
| Finite population correction | Optional for large populations | Optional for large populations |
The one-sample t-test is robust to violations of normality when n ≥ 30 because of the central limit theorem. Mild to moderate skew in the population has little effect on the t-test with moderate sample sizes. Severe outliers, however, can distort results at any sample size — use Winsorization or a nonparametric test like the Wilcoxon signed-rank test in those cases.
A common error is performing a z-test when σ is estimated from prior data rather than truly known. If you estimated σ from a previous study's sample, it carries sampling error itself — it is not the true population σ. The t-test is the correct choice. See the statistical assumptions guide for how to test each condition formally.
Interactive Test Selector
Answer four questions about your study and the selector will tell you which test to run, with a brief reason.
🔍 Which Test Should I Use?
5 Worked Examples
Each example uses the 6-step hypothesis testing procedure and shows the full arithmetic. The same problem is solved twice where both tests could apply, so you can see how the results compare.
Example 1 — One-Sample T-Test (σ Unknown)
Problem: A nutritionist believes the average daily sodium intake of adults in a city exceeds the WHO recommendation of 2,000 mg. A random sample of 18 adults yields x̄ = 2,310 mg with s = 480 mg. Test at α = 0.05.
s = 480 mg (sample SD)
n = 18
df = 17
Hypotheses: H₀: μ = 2,000 mg | H₁: μ > 2,000 mg (one-tailed, right)
Significance level: α = 0.05. One-tailed test; with df = 17, critical value from the t-distribution table is t* = 1.740.
Test selection: T-test. σ is unknown and n = 18 < 30, so the t-distribution is required. See the one-sample t-test guide.
Test statistic:
SE = s / √n = 480 / √18 = 480 / 4.243 = 113.12
t = (2,310 − 2,000) / 113.12 = 310 / 113.12 = 2.74
p-value: For t = 2.74 with df = 17 (one-tailed): p ≈ 0.007
Decision: p = 0.007 < 0.05 → Reject H₀. Also: t = 2.74 > t* = 1.740.
✅ Conclusion: At α = 0.05, there is statistically significant evidence (p = 0.007) that the average daily sodium intake in this city exceeds 2,000 mg. Because σ was unknown and n = 18, the t-test with df = 17 was the correct choice — a z-test would have been inappropriate here.
Example 2 — One-Sample Z-Test (σ Known)
Problem: A nationwide standardized test has a known population standard deviation of σ = 15 points. A local school's sample of 60 students scores x̄ = 103. The national mean is μ₀ = 100. At α = 0.05, does this school's average differ from the national mean?
σ = 15 (known population SD)
n = 60
Hypotheses: H₀: μ = 100 | H₁: μ ≠ 100 (two-tailed)
Significance level: α = 0.05. Two-tailed z-test critical values: ±1.96. See the full z-table.
Test selection: Z-test. σ = 15 is given as a known population parameter (from national test standardization), and n = 60 ≥ 30. Both conditions for the z-test are met.
Test statistic:
SE = σ / √n = 15 / √60 = 15 / 7.746 = 1.936
z = (103 − 100) / 1.936 = 3 / 1.936 = 1.549
p-value: For |z| = 1.549 (two-tailed): p ≈ 0.121
Decision: p = 0.121 > 0.05 → Fail to Reject H₀. Also: |z| = 1.549 < 1.96.
❌ Conclusion: There is not enough evidence (p = 0.121) to conclude this school's mean differs from the national average of 100. The 3-point difference is within the range expected from sampling variation when n = 60 and σ = 15.
Example 3 — Same Data, Both Tests: See the Difference
Problem: A manufacturer claims bolt tensile strength averages 500 N. A quality inspector samples n = 25 bolts and finds x̄ = 487 N with s = 30 N. Run both a t-test (treating σ as unknown) and a z-test (wrongly treating s as if it were σ) and compare the results at α = 0.05, two-tailed.
Hypotheses: H₀: μ = 500 N | H₁: μ ≠ 500 N (two-tailed)
SE: SE = 30 / √25 = 30 / 5 = 6.00 | Test statistic: (487 − 500) / 6 = −13 / 6 = −2.167
T-Test (correct): df = 24. Critical value = ±2.064. |t| = 2.167 > 2.064 → Reject H₀. p ≈ 0.040.
Z-Test (incorrect here, for illustration): Critical value = ±1.96. |z| = 2.167 > 1.96 → Reject H₀. p ≈ 0.030.
What changed: Same conclusion here, but the t-test gives p = 0.040 while the z-test gives p = 0.030. If the true mean were closer to 500 N, the discrepancy could flip the conclusion. The z-test gives artificially low p-values when σ is estimated, making it easier to reject H₀ than it should be.
⚠️ Key lesson: Both reject here, but using a z-test when σ is unknown inflates Type I error (false positives). The t-test with df = 24 is the correct test. Its critical value (2.064) is higher than z's (1.96) specifically to compensate for not knowing the true σ. Use the t-test calculator for this type of problem.
Example 4 — Two-Sample T-Test
Problem: A clinical trial compares a drug (n₁ = 30, x̄₁ = 142 mmHg, s₁ = 18) against a placebo (n₂ = 30, x̄₂ = 151 mmHg, s₂ = 20). Does the drug lower blood pressure significantly at α = 0.05?
Hypotheses: H₀: μ₁ = μ₂ | H₁: μ₁ < μ₂ (one-tailed: drug lowers BP)
Test selection: Two-sample Welch's t-test. σ for both groups is unknown. Full details at the two-sample t-test guide.
Test statistic:
SE = √(18²/30 + 20²/30) = √(10.8 + 13.33) = √24.13 = 4.913
t = (142 − 151) / 4.913 = −9 / 4.913 = −1.832
p-value: Welch's df ≈ 57. For t = −1.832 (one-tailed): p ≈ 0.036
Decision: p = 0.036 < 0.05 → Reject H₀.
✅ Conclusion: At α = 0.05, there is statistically significant evidence that the drug reduces blood pressure compared to the placebo (p = 0.036). The two-sample t-test was required because population SDs were unknown for both groups.
Example 5 — Z-Test for Proportions
Problem: A marketing team claims their email open rate is 25%. Of n = 400 emails sent in a new campaign, 88 were opened (p̂ = 0.22). At α = 0.05, does the campaign open rate differ from the claimed 25%?
p̂ = 88/400 = 0.22
p₀ = 0.25
n = 400
Hypotheses: H₀: p = 0.25 | H₁: p ≠ 0.25 (two-tailed)
Test selection: Z-test for proportions. Check conditions: np₀ = 400 × 0.25 = 100 ≥ 10 and n(1−p₀) = 300 ≥ 10. Both satisfied. Critical values: ±1.96.
Test statistic:
SE = √(0.25 × 0.75 / 400) = √(0.1875 / 400) = √0.000469 = 0.02165
z = (0.22 − 0.25) / 0.02165 = −0.03 / 0.02165 = −1.386
p-value: For |z| = 1.386 (two-tailed): p ≈ 0.166
Decision: p = 0.166 > 0.05 → Fail to Reject H₀.
❌ Conclusion: There is insufficient evidence (p = 0.166) to conclude the campaign's open rate differs from 25%. The observed 22% rate is within the range of sampling variability expected from a true 25% rate with n = 400. This is the one case where the z-test applies even though σ is not a quantity in the traditional sense — the proportion's variance is determined entirely by p₀, so there's nothing unknown to estimate. See the z-test calculator for proportion testing. For more on A/B testing, see how statistics powers A/B testing.
Interactive T-Test and Z-Test Calculator
Enter your data below. Select t-test when σ is unknown (the typical case), or z-test when σ is genuinely known. The calculator handles one-sample tests and all three tail directions.
🧮 One-Sample T-Test / Z-Test Calculator
For more test types, visit the dedicated t-test calculator (paired and two-sample), the z-test calculator, and the confidence interval calculator.
Common Mistakes and How to Avoid Them
| Mistake | Wrong Approach | Correct Approach |
|---|---|---|
| Using z-test when σ is unknown | Running z-test with s in place of σ "because n is large" | Use t-test. s ≠ σ regardless of sample size — t-test handles this correctly |
| Applying one-sample test to paired data | Running two separate one-sample t-tests (before and after) independently | Use the paired t-test on the differences d = after − before |
| Using z-test for proportions without checking conditions | Applying proportion z-test when np < 10 | Verify np₀ ≥ 10 and n(1−p₀) ≥ 10. If not, use Fisher's exact test |
| Treating a prior study's s as σ | Assuming s from a previous sample is the population σ and using a z-test | A sample SD from a previous study still carries estimation error — use t-test |
| Wrong degrees of freedom | Using df = n for one-sample t-test | Degrees of freedom = n − 1 for one-sample; use Welch's df formula for two-sample |
| Ignoring the direction of H₁ | Using two-tailed p-value when the hypothesis was directional | Set tail direction in H₁ before seeing data. One-tailed p = two-tailed p ÷ 2 (if in the right direction) |
Where Each Test Gets Used
Choosing the right test matters beyond the textbook. Here are the fields where each test appears in practice, and what the decision looks like in each context.
Clinical Research
Nearly always uses the t-test. Patient measurements (blood pressure, cholesterol, tumor markers) come from study samples. Population SDs for these outcomes are never truly known before the study.
Manufacturing QC
Often uses z-test. Long-established production lines can have genuine historical σ from thousands of measurements. When a process is well-understood, σ may legitimately be treated as known.
A/B Testing (Marketing)
Z-test for proportions (click-through rates, conversion rates). T-test for continuous outcomes (average session duration, revenue per visitor). See A/B test calculator.
Education Research
T-test is standard. Standardized tests publish national means, but the national SD applies to a heterogeneous population that differs from any specific school sample. Individual school σ is unknown.
Finance
Both tests appear. Portfolio return analysis typically uses t-test (σ of returns unknown ex ante). Proportion tests (default rates, fraud rates) use z-test when samples are large.
Biomedical Research
T-test dominates for biomarker comparisons between treatment groups. Z-test appears in large epidemiological studies comparing rates across populations with well-characterized SDs.
The Sampling Distribution Behind Each Test
The reason two separate tests exist comes down to a theoretical result in statistics called the distribution of the studentized mean. When σ is known:
But when you substitute s for σ, the ratio no longer follows N(0, 1). It follows a t-distribution with n − 1 degrees of freedom:
This is not a convention or a heuristic — it is a mathematical theorem. The t-distribution arises because s is itself a random variable (it varies from sample to sample), and combining two sources of randomness (x̄ and s) creates a distribution with heavier tails than the normal. The degrees of freedom parameter captures how much variability s has: small df (small n) means s is unreliable, so the tails are fat; large df means s is close to σ, so the tails thin out toward the normal.
For a deeper look at how sampling distributions work, see the central limit theorem guide and the sampling distributions overview.
What Are Degrees of Freedom?
Degrees of freedom is the one concept that separates the t-test from the z-test procedurally. The z-test has no degrees of freedom parameter — you simply look up a single fixed critical value table. The t-test requires you to specify df = n − 1 before consulting the t-table, because the distribution changes with every different sample size.
The intuition: when you compute s from n observations, you first compute the sample mean x̄ and then compute deviations from it. Because those deviations must sum to zero, only n − 1 of them are free to vary — the last one is determined by the others. So n − 1 is the degrees of freedom: the number of independent pieces of information in your estimate of variability.
One-sample t-test: df = n − 1. Two-sample (pooled) t-test: df = n₁ + n₂ − 2. Welch's two-sample t-test: df is computed from a more complex formula involving both sample sizes and SDs. Paired t-test: df = n_pairs − 1. Full details at the degrees of freedom guide.
Running These Tests in Software
Every major statistics package includes both tests, though their defaults and function names differ. Knowing which function to call prevents choosing the wrong test by mistake.
| Software | T-Test Command | Z-Test Command | Notes |
|---|---|---|---|
| Python (scipy) | scipy.stats.ttest_1samp(data, mu) | statsmodels.stats.weightstats.ztest | scipy defaults to t-test for means |
| R | t.test(x, mu = 100) | BSDA::z.test(x, sigma.x = σ) | Base R has t.test; z.test requires BSDA package |
| SPSS | Analyze → Compare Means → One-Sample T Test | Not natively available; use syntax ZTEST | SPSS defaults to t-test |
| Excel | =T.TEST() or Data Analysis ToolPak → t-Test | =Z.TEST(data, μ, σ) | Z.TEST requires σ as third argument |
| MATLAB | [h,p,ci,stats] = ttest(x, mu) | Not built-in; compute z manually | MATLAB does not have a built-in z-test for means |
| Minitab | Stat → Basic Statistics → 1-Sample t | Stat → Basic Statistics → 1-Sample Z | Minitab has both explicitly |
Notice that Python's scipy and R's base package default to the t-test, treating it as the correct choice for mean inference. This reflects modern statistical practice: when in doubt about whether σ is truly known, the t-test is the safer, more honest choice.
Frequently Asked Questions
Quick-Reference Summary
- σ unknown → T-test (this is the case in virtually all real research)
- σ known + n ≥ 30 → Z-test valid (but t-test still works and is more conservative)
- n < 30 → T-test regardless of what you think you know about σ
- Paired/before-after data → Paired t-test (compute d_i = after − before, then one-sample t-test on d)
- Comparing two means → Two-sample t-test (Welch's unless variances are clearly equal)
- Proportion testing (np ≥ 10) → Z-test for proportions
- T-test formula: t = (x̄ − μ₀) / (s / √n), compare to t(df = n − 1)
- Z-test formula: z = (x̄ − μ₀) / (σ / √n), compare to standard normal
- Both tests converge for large n — at df = 120, t ≈ z to two decimal places
- When in doubt: t-test is always the safer, more honest choice
Continue building your hypothesis testing foundation: Hypothesis Testing overview · Understanding P-Values · Type I & II Errors · Statistical Power · Effect Size · Confidence Intervals · Hypothesis Testing Examples