A t-test is a hypothesis test that compares means by dividing an observed difference by its estimated standard error and judging the result against the t distribution. In statistics, it is the standard tool for asking whether a sample mean differs from a reference value, or whether two group means differ by more than random sampling variation would explain.
The test was published in 1908 by William Sealy Gosset under the pen name “Student”, which is why it is also called Student’s t-test. Its key insight is that when the population variance is unknown and must be estimated from the sample, the test statistic follows a distribution with heavier tails than the normal distribution, especially for small samples.
How the t statistic is built
Every t-test computes a signal-to-noise ratio: the difference between means in the numerator and the standard error of that difference in the denominator. For a one-sample test, the statistic is the sample mean minus the hypothesized mean, divided by the sample standard deviation over the square root of the sample size.
The resulting value is compared with a t distribution that has a specific number of degrees of freedom, usually the sample size minus the number of estimated means. With few degrees of freedom the distribution is wide, so a larger t value is needed for significance. As degrees of freedom grow beyond roughly 30 to 100, the t distribution becomes nearly indistinguishable from the standard normal, and the t-test converges with the z-test.
The table below shows how the two-sided critical value at a 5 percent significance level shrinks as degrees of freedom increase.
| Degrees of freedom | Critical t value | Practical meaning |
|---|---|---|
| 2 | 4.30 | Very small samples need large effects |
| 5 | 2.57 | Still much stricter than normal |
| 10 | 2.23 | Moderate penalty for estimating variance |
| 30 | 2.04 | Close to the normal approximation |
| Infinite | 1.96 | Identical to the z-test |
Types of t-test and when each applies
Choosing the correct variant depends on the study design, specifically whether the observations are independent or paired and whether group variances can be assumed equal. Using the wrong variant changes the standard error and can produce misleading p-values.
| Variant | Question answered | Degrees of freedom |
|---|---|---|
| One-sample t-test | Does a mean differ from a fixed value | n minus 1 |
| Paired t-test | Do matched measurements change on average | Number of pairs minus 1 |
| Student’s t-test | Do two independent means differ, equal variances | n1 plus n2 minus 2 |
| Welch’s t-test | Do two independent means differ, unequal variances | Welch-Satterthwaite approximation |
The paired t-test is mathematically a one-sample test on the differences within each pair, which removes between-subject variation and often gives much greater statistical power. Many statisticians now recommend Welch’s t-test as the default for independent groups, because it performs well when variances are equal and remains reliable when they are not, particularly with unequal group sizes.
Assumptions behind a valid t-test
A t-test produces trustworthy p-values only when its assumptions hold reasonably well. The most important ones are independence of observations, an approximately normal sampling distribution of the mean and, for the classic two-sample form, equal variances.
- Independence is the most critical assumption. Clustered, repeated or time-correlated data violate it and make the test overconfident.
- Normality applies to the sampling distribution of the mean, not strictly to the raw data. Thanks to the central limit theorem, moderate samples tolerate skewed data, but small samples with strong skew or outliers do not.
- Equal variances matter only for the pooled Student version; Welch’s version relaxes this requirement.
- Interval or ratio measurement is assumed, because averaging ordinal ranks can distort conclusions.
Formal pre-tests such as Shapiro-Wilk for normality or Levene for variance equality are common but debated, since they lack power in small samples and flag trivial deviations in large ones. Visual checks such as Q-Q plots and boxplots, combined with knowledge of the data-generating process, are usually more informative.
The t-test compared with related tests
The t-test belongs to a family of parametric and nonparametric procedures for comparing groups. Its neighbors differ in how many groups they handle, what they assume about variance and whether they test means or other properties.
| Test | Compares | Prefer it when |
|---|---|---|
| Z-test | Means with known variance | Population variance is truly known |
| ANOVA | Means of three or more groups | Several groups would need many t-tests |
| Mann-Whitney U test | Distributions or ranks of two groups | Small skewed samples or ordinal data |
| Wilcoxon signed-rank test | Paired differences by rank | Paired data with heavy outliers |
| Chi-squared test | Frequencies of categories | Outcomes are counts, not measurements |
Running many pairwise t-tests instead of one ANOVA inflates the family-wise error rate: with ten independent comparisons at 0.05, the chance of at least one false positive is roughly 40 percent. A two-sample t-test is also equivalent to linear regression with a single binary predictor, which makes it easy to extend with covariates.
Interpreting results and avoiding common mistakes
A t-test reports a t value, degrees of freedom and a p-value, and good practice adds a confidence interval for the mean difference and an effect size such as Cohen’s d. The p-value states how surprising the data would be if the null hypothesis were true; it does not state the probability that the null hypothesis is true.
| Mistake | Consequence | Better practice |
|---|---|---|
| Treating paired data as independent | Lost power and wrong standard error | Use the paired t-test |
| Ignoring clustered observations | Falsely small p-values | Use mixed models or cluster-level means |
| Equating significance with importance | Trivial effects overstated | Report effect size and interval |
| Testing after peeking at data | Inflated false-positive rate | Preregister the hypothesis and sample size |
Choosing between one-tailed and two-tailed tests must happen before data collection. A one-tailed test halves the p-value for effects in the predicted direction, so switching after seeing results is a form of p-hacking. Sample size should be planned with a power analysis, because underpowered studies miss real effects and exaggerate the ones they detect.
In everyday language
A t-test helps answer a simple question: is the difference between two averages real, or could it just be luck?
Imagine two classes take the same exam and one class scores three points higher on average. If scores inside each class vary wildly, three points may mean nothing. If scores are tightly grouped, three points may be a genuine gap. The t-test weighs the gap against the natural scatter and the number of students, then says how likely such a gap would be by chance alone.
The main takeaway is that a small difference can matter and a large one can be noise, depending on how consistent the data are and how much of it exists.
Seen in the real world
A hospital quality team wants to know whether a new discharge checklist shortens patient stays. They compare 48 patients treated before the change with 52 patients treated after, recording length of stay in days. The averages are 5.6 days before and 4.9 days after, but the spreads differ noticeably, so the analyst chooses Welch’s t-test rather than the pooled version.
The test gives a t value of about 2.3 with roughly 93 degrees of freedom and a two-sided p-value near 0.02. The 95 percent confidence interval for the reduction runs from about 0.1 to 1.3 days, and Cohen’s d is around 0.46, a moderate effect.
The team reports the result as evidence of a modest reduction in stay length, while noting that a before-and-after design cannot rule out seasonal effects. They plan a staggered rollout across wards to confirm the finding.