t-test

Also known as: Student's t-test

On this page 7

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 freedomCritical t valuePractical meaning
24.30Very small samples need large effects
52.57Still much stricter than normal
102.23Moderate penalty for estimating variance
302.04Close to the normal approximation
Infinite1.96Identical to the z-test
Two-sided critical t values at alpha of 0.05

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.

VariantQuestion answeredDegrees of freedom
One-sample t-testDoes a mean differ from a fixed valuen minus 1
Paired t-testDo matched measurements change on averageNumber of pairs minus 1
Student’s t-testDo two independent means differ, equal variancesn1 plus n2 minus 2
Welch’s t-testDo two independent means differ, unequal variancesWelch-Satterthwaite approximation
Main t-test variants

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 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.

TestComparesPrefer it when
Z-testMeans with known variancePopulation variance is truly known
ANOVAMeans of three or more groupsSeveral groups would need many t-tests
Mann-Whitney U testDistributions or ranks of two groupsSmall skewed samples or ordinal data
Wilcoxon signed-rank testPaired differences by rankPaired data with heavy outliers
Chi-squared testFrequencies of categoriesOutcomes are counts, not measurements
Alternatives and when to prefer them

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.

MistakeConsequenceBetter practice
Treating paired data as independentLost power and wrong standard errorUse the paired t-test
Ignoring clustered observationsFalsely small p-valuesUse mixed models or cluster-level means
Equating significance with importanceTrivial effects overstatedReport effect size and interval
Testing after peeking at dataInflated false-positive ratePreregister the hypothesis and sample size
Typical errors in applying the t-test

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.