The paired t-test is a formula that converts two related measurements per subject — a before-and-after score, say — into a single difference score, then tests whether the average of those differences departs from zero by more than chance explains. It is the formula half of a design question; the matching design question is answered in full in Statohub’s paired vs. independent t-test guide. This article works through the t-test equation itself: the general ratio every version shares, the paired difference t-test formula in full, the two-sample t-test formula (pooled and Welch), and fully computed numeric examples for both.

Key takeaways

Point Details
Every t-test equation is the same ratio An observed effect divided by its standard error — the paired, two-sample, and one-sample formulas only change what "effect" and "standard error" mean.
The paired t-test formula collapses to one sample It turns n pairs into n difference scores, then runs the one-sample formula on those differences: t = d̄ / (s_d / √n), with df = n − 1.
The two-sample t-test formula needs one extra decision Pool the two variances into one standard error if they look similar, or use the Welch-adjusted formula if they do not — see the comparison table below.
Degrees of freedom depend on pairs, not raw measurements A paired design with 6 subjects measured twice has df = 5 (6 pairs minus 1), never df = 10.
Software defaults disagree R's t.test() defaults to Welch's unequal-variance formula; Python's scipy.stats.ttest_ind() defaults to the pooled, equal-variance formula — check before trusting either blindly.

Quick Checklist: How Do You Pick and Compute the Right T-Test Formula?

Before touching a formula, nail down the structure of your data — it decides which equation applies and what each symbol in it means.

Quick checklist: picking and computing the right t-test formula

  • Decide paired or two-sample Same subjects measured twice (or deliberately matched pairs) means paired; two separate, unrelated groups means two-sample. See the decision guide linked below for edge cases.
  • Paired: compute the difference scores first dᵢ = measurement 1 − measurement 2 for every pair, computed in the same direction for every row.
  • Two-sample: check whether the variances look similar Close sample standard deviations support the pooled formula; noticeably different ones call for the Welch-adjusted formula instead.
  • Count degrees of freedom correctly df = n − 1 for paired data (n = number of pairs); df = n₁ + n₂ − 2 for the pooled two-sample formula.
  • Compute t, then compare or convert Compare |t| against a critical value for your df and α, or convert t directly to a p-value.
  • Report t, df, and p together A test result is only complete with all three numbers, not the p-value alone.

What Is the T-Test Equation?

Every t-test equation, whatever the design, reduces to the same structural ratio:

t = (observed effect) / (standard error of that effect)

The student t-test formula gets its name from William Sealy Gosset, who worked out the distribution while analyzing small samples of hops and barley at the Guinness brewery in Dublin and published it under the pen name “Student.” He needed a distribution that stayed valid when the sample size was too small for the normal approximation to hold, because replacing the unknown population standard deviation σ with the sample standard deviation s introduces extra uncertainty that a normal curve understates. OpenStax’s Introductory Statistics, §8.2 recounts how Gosset ran into this problem. The practical result is a distribution with heavier tails than the normal curve, so a t-statistic has to clear a higher threshold than the equivalent z-score would need before a result counts as significant — the t-test vs. z-test guide covers exactly when each distribution applies.

The table below lines up the t-test formula for each common design side by side. The chi-square test, built on the chi-square distribution, and ANOVA’s F-statistic follow the same observed-over-standard-error logic with different symbols, as the test statistic guide covers in detail.

The t-test equation by design
Design T-test formula Degrees of freedom
One-sample t = (x̄ − μ₀) / (s / √n) n − 1
Paired (paired difference t-test) t = d̄ / (s_d / √n) n − 1 (n = number of pairs)
Two-sample, pooled (equal variances) t = (x̄₁ − x̄₂) / (s_p × √(1/n₁ + 1/n₂)) n₁ + n₂ − 2
Two-sample, Welch's (unequal variances) t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂) Welch–Satterthwaite approximation (non-integer)

Whether to use the paired row or one of the two-sample rows is a question about how your data were collected, not about the formulas themselves — the full decision rule, with examples of each data structure, lives in the paired vs. independent t-test guide.

How Do You Derive the Paired Difference T-Test Formula From Your Data?

The paired difference t-test starts by reducing two columns of related numbers to one column of differences. For each of the n pairs, compute:

dᵢ = (measurement 1)ᵢ − (measurement 2)ᵢ

using the same subtraction direction for every pair. From the n difference scores, compute their mean and standard deviation, then plug both into the one-sample t formula:

d̄ = (Σ dᵢ) / n

s_d = √( Σ(dᵢ − d̄)² / (n − 1) )

t = d̄ / (s_d / √n)

NIST/SEMATECH’s e-Handbook, §7.3.1.1 — Analysis of Paired Observations defines paired data precisely this way: two samples are paired when the i-th measurement in the first sample is naturally tied to the i-th measurement in the second, and builds this exact formula from that definition. OpenStax’s Introductory Statistics, §10.4 — Matched or Paired Samples describes the same reduction: once the differences are calculated, the population mean of those differences is tested with a Student’s-t test for a single population mean, using n − 1 degrees of freedom. The null hypothesis is H₀: the true mean difference equals zero — the null hypothesis guide covers how to state that formally for a one-tailed or two-tailed alternative. The result follows a t-distribution with df = n − 1, where n counts pairs, not the 2n raw measurements you started with.

The data are said to be paired if the i-th measurement on the first sample is naturally paired with the i-th measurement on the second sample.

NIST/SEMATECH e-Handbook of Statistical Methods, §7.3.1.1

Because s_d is computed on the differences rather than on the raw scores, variation that is common to both measurements on the same subject cancels out before it ever reaches the formula — that is the mechanical reason the paired difference t-test formula is usually more powerful than treating the same data as two independent groups.

What Is the Two-Sample T-Test Formula?

The two-sample t-test (also called the 2 sample t-test, or the t test for two samples) compares the means of two separate groups directly, without reducing anything to differences first. NIST/SEMATECH’s e-Handbook, §7.3.1 — Do Two Processes Have the Same Mean? derives the formula in both forms below, depending on whether the two population variances can be assumed equal; OpenStax’s Introductory Statistics, §10.1 covers only the unequal-variance (Aspin-Welch) form and explicitly advises against pooling the two sample variances.

Equal variances (pooled). First pool the two sample variances, weighted by their degrees of freedom, into a single pooled standard deviation s_p:

s_p = √( ((n₁ − 1)s₁² + (n₂ − 1)s₂²) / (n₁ + n₂ − 2) )

t = (x̄₁ − x̄₂) / (s_p × √(1/n₁ + 1/n₂))

with df = n₁ + n₂ − 2.

Unequal variances (Welch’s). Replace the pooled term with each group’s own variance divided by its own sample size:

t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)

The degrees of freedom are no longer a clean integer; they come from the Welch–Satterthwaite approximation, which NIST’s handbook gives in full. Welch’s version remains valid whether or not the variances are actually equal. Software defaults differ on which formula runs by default: R’s t.test() function defaults to Welch’s formula (var.equal = FALSE), while Python’s scipy.stats.ttest_ind() defaults the other way, to the pooled formula (equal_var=True).

A quick illustration of the pooled formula: a manufacturing line samples n₁ = 8 units from Process A (mean fill weight x̄₁ = 74 g, s₁ = 6 g) and n₂ = 8 units from Process B (x̄₂ = 68 g, s₂ = 8 g). Their sample standard deviations are close enough to pool:

s_p = √( (7 × 36 + 7 × 64) / 14 ) = √(700 / 14) = √50 ≈ 7.071

t = (74 − 68) / (7.071 × √(1/8 + 1/8)) = 6 / (7.071 × 0.5) = 6 / 3.536 ≈ 1.70

df = 8 + 8 − 2 = 14. At α = 0.05 two-tailed, NIST’s table of critical values for the Student’s t-distribution gives a critical value of about 2.145 at df = 14, so |t| = 1.70 falls short and the two processes’ means are not shown to differ at the 5% level with this sample size.

Calculate a Paired T-Test

The calculator below runs the one-sample student t-test formula, which also handles the paired case directly. For a paired t-test, enter d̄ (the mean of your difference scores) as the sample mean, s_d (the standard deviation of those differences) as the sample standard deviation, the number of pairs as n, and 0 as the hypothesized mean, since H₀ states that the true mean difference is zero.

Calculator

T-Test Calculator

Enter values and compute the result.

With the default values shown (sample mean 105, hypothesized mean 100, standard deviation 15, n = 25): SE = 15 / √25 = 3.0, t = (105 − 100) / 3 = 1.667, df = 24, and the two-tailed p-value works out to about 0.109 — above 0.05, so H₀ is not rejected with these defaults. The two-sample formula above does not take raw two-group data as input here; compute t by hand with the pooled or Welch formula, then enter that t-statistic and its degrees of freedom into the standalone p-value calculator to get an exact p-value.

What Do You Need to Check Before Running a T-Test?

All versions of the t-test equation share four conditions worth confirming before you trust the result.

  • Independence. Observations are independent of each other within a group; in a paired design, the pairs themselves must be independent even though the two readings inside each pair are deliberately correlated.
  • Approximate normality. The data (or the difference scores, in a paired design) should be roughly normal, or the sample large enough for the central limit theorem to cover minor departures — OpenStax’s guidance above notes that distribution shape stops mattering once both samples are reasonably large, and matters most when either sample is small.
  • Interval or ratio measurement. The outcome must sit on a continuous scale. For ranked or ordinal data, the Mann-Whitney U test or a Wilcoxon signed-rank test are the standard nonparametric substitutes.
  • Equal variances, for the pooled two-sample formula only. This assumption does not apply to the paired formula or to Welch’s two-sample formula, both of which sidestep it entirely.

These four conditions, and what the paired and two-sample designs share beyond the formula itself, are covered in full in the paired vs. independent t-test guide’s assumptions section.

How Do You Run a Paired or Two-Sample T-Test in Software?

Each major tool keeps the paired and two-sample t-test formulas behind separate function calls or arguments, and mixing them up is an easy way to get the wrong standard error.

Running a paired vs. two-sample t-test in R, Python, and Excel
Tool Paired t-test Two-sample t-test
R t.test(before, after, paired = TRUE) t.test(group1, group2) # Welch by default
Python (SciPy) scipy.stats.ttest_rel(before, after) scipy.stats.ttest_ind(group1, group2, equal_var=False)
Excel T.TEST(array1, array2, tails, 1) T.TEST(array1, array2, tails, 2 or 3)

In R, t.test() switches entirely from the two-sample Welch formula to the paired difference formula the moment you add paired = TRUE — it then needs the two raw vectors to be the same length and in matching order, since it computes the differences internally. In Python, scipy.stats.ttest_rel() is the paired counterpart to scipy.stats.ttest_ind(); the independent-samples function defaults to the pooled, equal-variance formula (equal_var=True) and needs that argument flipped to False to switch to Welch’s. Excel’s T.TEST function takes a type argument that picks the formula directly: 1 for paired, 2 for the pooled two-sample formula, and 3 for Welch’s unequal-variance formula — all three return a p-value rather than the t-statistic itself, so pair the function with a manual t calculation if you need the statistic too.

A Worked Example: Paired T-Test for a Six-Week Diet Programme

A nutritionist tests whether a six-week diet programme reduces body weight. Six participants are weighed before and after, in pounds. Pairing each participant with themselves removes the large person-to-person differences in starting weight from the analysis.

ParticipantBefore (lb)After (lb)d = Before − After
11851805
21921857
31701691
41781726
52031967
61901837
Paired t-test decision process Five steps: compute the differences, find the mean and standard deviation of the differences, compute the t statistic, find degrees of freedom, then compare to the critical value and decide. 1 Compute thedifferences d = Before - After foreach of the 6participants: 5, 7, 1,6, 7, 7. 2 Find mean and SDof d d-bar = 33 / 6 = 5.5 lb.s_d = sqrt(27.5 / 5) =2.345 lb. 3 Compute the tstatistic t = 5.5 / (2.345 /sqrt(6)) = 5.5 / 0.957 =5.74. 4 Find degrees offreedom df = 6 - 1 = 5. 5 Compare and decide Critical value at df=5,two-tailed 0.05, is2.571. 5.74 > 2.571, soreject H0.
Figure 1. The five-step path from the raw before/after data to a reject/fail-to-reject decision for the diet programme example.
  1. Mean difference. d̄ = (5 + 7 + 1 + 6 + 7 + 7) / 6 = 33 / 6 = 5.5 lb.
  2. Standard deviation of the differences. The squared deviations from 5.5 are 0.25, 2.25, 20.25, 0.25, 2.25, and 2.25, summing to 27.50. So s_d² = 27.50 / (6 − 1) = 5.50, and s_d = √5.50 ≈ 2.345 lb.
  3. Standard error and t. SE = s_d / √n = 2.345 / √6 ≈ 2.345 / 2.449 ≈ 0.957 lb. t = d̄ / SE = 5.5 / 0.957 ≈ 5.74.
  4. Degrees of freedom. df = n − 1 = 6 − 1 = 5.
  5. Decision. At α = 0.05 two-tailed, NIST’s table of critical values for the Student’s t-distribution gives a critical t-value of about 2.571 at df = 5. Since |t| = 5.74 exceeds 2.571, reject H₀: the programme produced a statistically significant reduction in body weight (mean decrease = 5.5 lb, t(5) = 5.74, p ≈ 0.002).

Individual starting weights in this sample ranged from 170 lb to 203 lb — a 33 lb spread that would swamp the 5.5 lb average reduction if the six before-scores and six after-scores had instead been analyzed as two unrelated groups of six. Pairing each person with their own earlier measurement removed that between-subject noise from the calculation entirely, which is the practical reason the paired difference t-test formula produced such a large t-statistic here.

Common Mistakes When Applying the T-Test Formula

  • Plugging raw before/after scores into a two-sample formula. Running the pooled or Welch formula directly on the “before” column and the “after” column, instead of first reducing them to difference scores, discards the within-subject correlation that makes the paired design powerful and tends to produce a far smaller, less significant t-statistic. Fix it by computing dᵢ for every pair before you touch the t formula.
  • Counting raw measurements instead of pairs for degrees of freedom. Six subjects measured twice gives df = 5 (six pairs minus one), not df = 10. Fix it by asking how many independent difference scores you actually have before applying n − 1.
  • Defaulting to the pooled two-sample formula without checking the variances. The pooled formula assumes the two groups share a population variance; when the sample standard deviations differ and the two group sizes differ, the pooled test’s actual Type I error rate drifts away from the stated α (too small or too large, depending on which group has the larger variance and which has the larger n). Fix it by comparing s₁ and s₂ first, and reaching for Welch’s formula whenever they look meaningfully different — Welch’s formula stays valid regardless of group size.
  • Subtracting in inconsistent directions. If some differences are computed as Before − After and others as After − Before, positive and negative values cancel out and bias d̄ toward zero. Fix it by picking one subtraction order and verifying every row follows it before summing.
  • Reporting the p-value alone. A complete result states the t-statistic, the degrees of freedom, and the p-value together — for example, t(5) = 5.74, p ≈ 0.002 — because the t and df let a reader judge the effect size and the test used, not just whether it cleared 0.05.
  • Choosing the wrong tail direction. A two-tailed test checks whether the effect differs from zero in either direction; a one-tailed test checks only one predicted direction and should only be chosen before the data are collected, based on the research question, not after seeing which direction a nearly-significant result happened to point.

Statohub’s Take on the T-Test Formula

Statohub’s position is that the paired and two-sample t-test formulas are worth learning as one idea with two inputs, not two unrelated equations. Both divide an observed effect by a standard error built from exactly the data you have — a column of differences in the paired case, two separate groups in the two-sample case. Once that shared structure is visible, deciding which standard error to build is a data-structure question, answered once per study, rather than a fresh formula to memorize every time.

Put the T-Test Formula to Work With Statohub’s Tools

The calculator above runs the paired difference t-test formula directly once you convert your data to difference scores, and the standalone t-test calculator gives the same tool a full page. For the decision of which formula your study actually needs, the paired vs. independent t-test guide covers the full rule with its own worked examples, and the test statistic guide covers degrees of freedom and critical values for every test in this family, not just the t-test. Statohub’s Inferential Statistics hub connects this page to hypothesis setup and p-values, and the full calculators hub lists every tool for checking your own numbers.

Sources

Sources

  1. NIST/SEMATECH e-Handbook — 7.3.1.1. Analysis of Paired Observations NIST
  2. NIST/SEMATECH e-Handbook — 7.3.1. Do Two Processes Have the Same Mean? NIST
  3. NIST/SEMATECH e-Handbook — 1.3.6.7.2. Critical Values of the Student’s-t Distribution NIST
  4. OpenStax — 8.2 A Single Population Mean using the Student t Distribution, Introductory Statistics OpenStax
  5. OpenStax — 10.1 Two Population Means with Unknown Standard Deviations, Introductory Statistics OpenStax
  6. OpenStax — 10.4 Matched or Paired Samples, Introductory Statistics OpenStax
  7. scipy.stats.ttest_rel — SciPy v1.18.0 Manual SciPy
  8. scipy.stats.ttest_ind — SciPy v1.18.0 Manual SciPy
  9. R: Student’s t-Test (t.test) The R Project
  10. T.TEST function Microsoft Support

FAQ

Frequently asked questions

What Is the Paired T-Test Formula?
The paired t-test formula is t = d̄ / (s_d / √n), where d̄ is the mean of the per-pair difference scores, s_d is their standard deviation, and n is the number of pairs. It is structurally identical to the one-sample t formula applied to the differences rather than the raw measurements, and its degrees of freedom are n − 1.
What Is the T-Test Equation for Two Samples?
With equal variances assumed, t = (x̄₁ − x̄₂) / (s_p × √(1/n₁ + 1/n₂)), using the pooled standard deviation s_p and df = n₁ + n₂ − 2. When the variances cannot be assumed equal, Welch’s version replaces the denominator with √(s₁²/n₁ + s₂²/n₂) and estimates degrees of freedom with the Welch–Satterthwaite approximation instead of a clean integer formula.
How Do You Know Whether to Use the Paired or Two-Sample T-Test Formula?
Use the paired formula whenever each observation in one set has a specific, natural partner in the other set, most commonly the same subject measured twice. Use a two-sample formula when the two sets come from different, unrelated subjects with no such pairing. The paired vs. independent t-test guide covers the full decision rule and edge cases in detail.
How Many Degrees of Freedom Does a Paired T-Test Have?
A paired t-test has df = n − 1, where n is the number of pairs, not the total number of raw measurements. Six subjects measured before and after a treatment produce six difference scores and df = 5, even though 12 individual readings were recorded. The test statistic guide covers how degrees of freedom are counted for other hypothesis tests.
Can You Run a Paired T-Test With a One-Sample T-Test Calculator?
Yes. Compute the difference score for every pair, then enter the mean of those differences as the sample mean, their standard deviation as the sample standard deviation, the number of pairs as n, and zero as the hypothesized mean, since the paired null hypothesis states that the true mean difference is zero. The calculator above runs exactly this formula.
How Do You Compute a Paired or Two-Sample T-Test in Excel or Python?
In Excel, T.TEST’s type argument picks the formula: 1 for paired, 2 for the pooled two-sample formula, and 3 for Welch’s unequal-variance formula. In Python’s SciPy, scipy.stats.ttest_rel() runs the paired formula on two equal-length arrays, while scipy.stats.ttest_ind() runs the two-sample formula and takes an equal_var argument to switch between the pooled and Welch versions.
How Do You Interpret the P-Value From a T-Test?
A t-test’s p-value is the probability of seeing a t-statistic at least this extreme if the null hypothesis were true. If p falls below your chosen significance level α (typically 0.05), reject H₀ and call the result statistically significant. A p-value above α means the data are consistent with H₀, but that is not proof the null hypothesis is true — only that this sample did not produce strong enough evidence against it. Report the p-value alongside the t-statistic, degrees of freedom, an effect size, and, where possible, a confidence interval for the mean difference.