Statistical Tests Open Access

Paired t-test: When, Why, and How to Use It

Diagram showing paired before-and-after measurements for the same subjects connected by lines, illustrating the within-subject differences analyzed by a paired t-test.
Figure 1. In a paired t-test, each subject is measured twice-once under each condition-and the test analyzes the distribution of within-subject differences rather than the two raw samples.

Introduction

The paired t-test (also called the paired sample t-test or dependent t-test) checks whether the average difference between two related measurements is statistically significant. If you have ever measured the "before" and "after" of the same subject-a blood pressure reading before and after a drug, a test score before and after a training program, weight at week 0 and week 8-this is usually the test you are looking for.

Diagram showing paired before-and-after measurements for the same subjects connected by lines, illustrating the within-subject differences analyzed by a paired t-test.
Figure 1. Each subject contributes one "before" value and one "after" value. The paired t-test analyzes the differences between these connected points, not the two groups of raw scores in isolation.

By the end of this article you will be able to state exactly when a paired t-test applies, compute one completely by hand on two different worked examples, interpret the result correctly alongside an effect size and confidence interval, and run the same test in three lines of Python with scipy.stats.ttest_rel.

What Is a Paired t-test?

The paired t-test compares two sets of measurements taken from the same subjects-once under one condition, once under another. Instead of comparing two independent groups, it looks at the difference within each pair and asks: on average, is that difference meaningfully different from zero?

It exists because it is built specifically for repeated or matched measurements. By focusing on the differences between pairs, it automatically removes person-to-person variation that has nothing to do with the treatment-making it more sensitive than comparing two separate, unrelated groups with an independent t-test.

Core idea in one line: reduce two related samples down to a single sample of differences, then run a one-sample t-test on that single sample of differences against a hypothesized mean of zero.

When to Use It

Use a paired t-test when the same subjects are measured twice (before and after an intervention), or when observations are naturally matched in pairs (twins, left eye vs. right eye, matched case-control pairs). The key requirement: the two samples are not independent-each value in sample A is linked to exactly one value in sample B.

ScenarioMeasurement 1Measurement 2
Training programScore before trainingScore after training
Medication trialBlood pressure before drugBlood pressure after drug
Weight loss dietWeight at week 0Weight at week 8
A/B testing (same users)Time on page (old UI)Time on page (new UI)
Matched case-controlOutcome in caseOutcome in matched control
Bilateral organ studyMeasurement, left eyeMeasurement, right eye

Key Assumptions

  • Paired/dependent samples. Each observation in group 1 must correspond to exactly one observation in group 2.
  • Differences are approximately normal. The test relies on the distribution of the paired differences, not the raw scores, being roughly normal-especially important with small samples.
  • Continuous data. Scores, measurements, or any interval/ratio-scale variable-not categories.
  • No major outliers in the differences. Since the test relies on the mean difference, a few extreme outliers can distort the result.
  • Independence across pairs. One subject's before/after difference should not influence another subject's difference.
Common mistake: checking whether the "before" scores and "after" scores are each normally distributed. That is not the assumption. What must be roughly normal is the set of differences (after − before) for each subject-a distinct quantity from either raw sample.

Hypotheses

The paired t-test formally tests the mean of the differences (\( \bar{d} \)) between paired observations:

  • Null Hypothesis (\( H_0 \)): the mean difference between paired observations is zero (\( \mu_d = 0 \))-i.e., the intervention had no real effect.
  • Alternative Hypothesis (\( H_1 \)): the mean difference is not zero (\( \mu_d \neq 0 \))-i.e., there is a real effect.

(For one-tailed tests, \( H_1 \) can instead state the difference is specifically greater than or less than zero, depending on the direction being tested-for example \( \mu_d > 0 \) if you only care whether scores improved.)

The Formula, Explained

For \( n \) pairs, let \( d_i = x_{i,\text{after}} - x_{i,\text{before}} \) be the difference for subject \( i \). The test statistic is:

\[ t = \frac{\bar{d}}{s_d / \sqrt{n}} \]

where:

  • \( \bar{d} = \dfrac{1}{n}\sum_{i=1}^{n} d_i \) is the mean of the paired differences,
  • \( s_d = \sqrt{\dfrac{1}{n-1}\sum_{i=1}^{n}(d_i - \bar{d})^2} \) is the sample standard deviation of the differences,
  • \( n \) is the number of pairs.

This \( t \) value is compared against a Student's t-distribution with \( n - 1 \) degrees of freedom to obtain a p-value. Structurally, this is exactly the formula for a one-sample t-test applied to the single column of differences, tested against a hypothesized mean of zero-which is precisely why the paired t-test is sometimes described as "a one-sample t-test in disguise."

Worked Example 1: A Small Numerical Example by Hand

Suppose a physiotherapist measures grip strength (in kg) for 5 patients before and after a 4-week hand exercise program.

PatientBeforeAfterDifference \( d_i \)
12831+3
22527+2
33029−1
42226+4
52729+2

Step 1: Compute the mean difference

\[ \bar{d} = \frac{3 + 2 + (-1) + 4 + 2}{5} = \frac{10}{5} = 2.0 \]

Step 2: Compute the standard deviation of the differences

First, find each squared deviation from \( \bar{d} = 2.0 \):

\[ \begin{aligned} (3 - 2)^2 &= 1 \\ (2 - 2)^2 &= 0 \\ (-1 - 2)^2 &= 9 \\ (4 - 2)^2 &= 4 \\ (2 - 2)^2 &= 0 \end{aligned} \]

Sum of squared deviations \( = 1 + 0 + 9 + 4 + 0 = 14 \). With \( n - 1 = 4 \) degrees of freedom:

\[ s_d = \sqrt{\frac{14}{4}} = \sqrt{3.5} \approx 1.8708 \]

Step 3: Compute the t-statistic

\[ t = \frac{\bar{d}}{s_d / \sqrt{n}} = \frac{2.0}{1.8708 / \sqrt{5}} = \frac{2.0}{1.8708 / 2.2361} = \frac{2.0}{0.8367} \approx 2.390 \]

Step 4: Compare against the critical value

With \( df = n - 1 = 4 \) and a two-tailed test at \( \alpha = 0.05 \), the critical value from the t-distribution table is \( t_{0.025, 4} = 2.776 \). Since our computed \( |t| = 2.390 \) is less than 2.776, we fail to reject \( H_0 \) at the 5% level-the corresponding two-tailed p-value works out to approximately 0.075, which is above 0.05.

Interpretation. Even though grip strength improved by an average of 2 kg, with only 5 patients the evidence is not quite strong enough to rule out chance at the conventional 5% threshold. This is a realistic illustration of how small sample sizes can leave a real-looking effect statistically inconclusive-notice this is exactly why effect size and confidence intervals matter alongside the raw p-value, not instead of it.

Worked Example 2: A Training Program (Six Students)

Suppose 6 students take a mock test, attend a 2-week training program, and then retake a similar test. We want to know if the training improved scores.

StudentBeforeAfterDifference
16268+6
27479+5
35865+7
48180−1
56975+6
67077+7

Step 1: Mean of the differences

\[ \bar{d} = \frac{6+5+7+(-1)+6+7}{6} = \frac{30}{6} = 5.0 \]

Step 2: Standard deviation of the differences

Squared deviations from \( \bar{d} = 5.0 \):

\[ \begin{aligned} (6-5)^2 &= 1 \\ (5-5)^2 &= 0 \\ (7-5)^2 &= 4 \\ (-1-5)^2 &= 36 \\ (6-5)^2 &= 1 \\ (7-5)^2 &= 4 \end{aligned} \]

Sum \( = 1+0+4+36+1+4 = 46 \). With \( n-1 = 5 \):

\[ s_d = \sqrt{\frac{46}{5}} = \sqrt{9.2} \approx 3.0332 \]

Step 3: t-statistic

\[ t = \frac{5.0}{3.0332 / \sqrt{6}} = \frac{5.0}{3.0332 / 2.4495} = \frac{5.0}{1.2383} \approx 4.038 \]

Step 4: Decision

With \( df = 5 \), the two-tailed critical value at \( \alpha = 0.05 \) is \( t_{0.025,5} = 2.571 \). Since \( 4.038 > 2.571 \), we reject \( H_0 \). The exact two-tailed p-value is approximately 0.0099, well below 0.05-the training program appears to have produced a statistically significant improvement.

This second example is deliberately chosen so its numbers match the Python walkthrough in the next section, letting you verify the hand calculation against scipy.stats.ttest_rel directly.

Effect Size (Cohen's d for Paired Samples)

A p-value tells you whether an effect is likely to be real; it says nothing about how large that effect is. For paired data, the standard effect size is Cohen's d for paired samples, computed by standardizing the mean difference by the standard deviation of the differences:

\[ d = \frac{\bar{d}}{s_d} \]

Using Worked Example 2: \( d = \dfrac{5.0}{3.0332} \approx 1.65 \). By Cohen's conventional benchmarks (\( d \approx 0.2 \) small, \( 0.5 \) medium, \( 0.8 \) large), a \( d \) of 1.65 is a very large effect-consistent with the low p-value found above.

Cohen's dInterpretation
~0.2Small effect
~0.5Medium effect
~0.8Large effect
1.0+Very large effect

Confidence Interval for the Mean Difference

A 95% confidence interval for \( \mu_d \) is often more informative than the p-value alone, since it shows the plausible range of the true effect size in the original units:

\[ \bar{d} \pm t_{\alpha/2, \, n-1} \cdot \frac{s_d}{\sqrt{n}} \]

For Worked Example 2, with \( \bar{d} = 5.0 \), \( s_d/\sqrt{n} = 1.2383 \), and \( t_{0.025,5} = 2.571 \):

\[ 5.0 \pm 2.571 \times 1.2383 = 5.0 \pm 3.184 \]

This gives a 95% CI of approximately [1.82, 8.18] points. Since the entire interval lies above zero, it agrees with the earlier rejection of \( H_0 \)-and gives a concrete, interpretable range for the likely true improvement, rather than just a binary significant/not-significant verdict.

Python Example

You can run this test in one line using scipy.stats.ttest_rel:

from scipy import stats
import numpy as np

before = [62, 74, 58, 81, 69, 70]
after  = [68, 79, 65, 80, 75, 77]

t_stat, p_value = stats.ttest_rel(after, before)

print(f"t-statistic: {t_stat:.3f}")
print(f"p-value: {p_value:.4f}")

# Effect size: Cohen's d for paired samples
diffs = np.array(after) - np.array(before)
cohens_d = diffs.mean() / diffs.std(ddof=1)
print(f"Mean difference: {diffs.mean():.2f}")
print(f"Cohen's d: {cohens_d:.3f}")

# 95% confidence interval for the mean difference
n = len(diffs)
se = diffs.std(ddof=1) / np.sqrt(n)
t_crit = stats.t.ppf(0.975, df=n - 1)
ci_low, ci_high = diffs.mean() - t_crit * se, diffs.mean() + t_crit * se
print(f"95% CI: [{ci_low:.2f}, {ci_high:.2f}]")

Output:

t-statistic: 4.038
p-value: 0.0099
Mean difference: 5.00
Cohen's d: 1.649
95% CI: [1.82, 8.18]

Every number here matches the hand calculation in Worked Example 2 exactly-ttest_rel(after, before) internally computes \( d_i = \text{after}_i - \text{before}_i \), then applies precisely the formula from the Formula section.

Checking Normality of the Differences

Before trusting the p-value, it is good practice to sanity-check the normality assumption on the differences themselves, e.g., with a Shapiro-Wilk test:

shapiro_stat, shapiro_p = stats.shapiro(diffs)
print(f"Shapiro-Wilk p-value: {shapiro_p:.4f}")
# If shapiro_p < 0.05, the normality assumption is questionable;
# consider the Wilcoxon Signed-Rank Test instead (see Section 16).

With only \( n = 6 \) observations, the Shapiro-Wilk test itself has very low power to detect non-normality-in practice, small paired studies are often evaluated together with a visual check (a Q-Q plot of the differences) rather than relying on a formal test alone.

How to Interpret Results

The significance level \( \alpha = 0.05 \) is the standard threshold used to decide whether a result is "statistically significant."

ConditionInterpretation
\( p < 0.05 \)Reject \( H_0 \)-the difference is statistically significant; the effect is unlikely due to chance.
\( p \geq 0.05 \)Fail to reject \( H_0 \)-not enough evidence of a real difference; could be due to random variation.
Note. A low p-value does not measure the size of the effect-it only tells you the observed difference is unlikely under the "no effect" assumption. Always look at the mean difference and effect size alongside the p-value, as demonstrated in Worked Example 1, where a real-looking 2 kg improvement was not statistically significant with only 5 patients.

Checking Assumptions in Practice

  • Normality of differences: a histogram or Q-Q plot of \( d_i \) values; formally, a Shapiro-Wilk test, keeping in mind its low power at small \( n \).
  • Outliers: a boxplot of the differences quickly flags any subject whose change is far outside the rest-worth investigating before trusting the mean difference.
  • Independence across pairs: a design question, not something visible in the data itself-confirm subjects did not influence each other's before/after change (e.g., students discussing answers between tests).
  • Sample size: the Central Limit Theorem offers some robustness to mild non-normality as \( n \) grows, but with very small samples (roughly \( n < 15 \)) the normality assumption matters more, as seen in both worked examples above.

Advantages

  • More statistically powerful than an independent t-test, since it removes between-subject variability.
  • Needs a smaller sample size to detect a real effect, since each subject acts as their own control.
  • Simple to compute and widely supported (Excel, Python, R, SPSS all implement it directly).
  • Directly interpretable: the mean difference is in the original measurement units, unlike some other test statistics.

Limitations

  • Only works for exactly two related measurements-not three or more time points (use repeated-measures ANOVA instead).
  • Sensitive to outliers in the differences, which can distort the t-statistic, as illustrated by the single negative difference in both worked examples above.
  • Assumes the differences are roughly normal; this can break down with small, skewed samples.
  • Cannot be used if your two samples come from different, unrelated subjects.

When NOT to Use It

  • Independent t-test: use instead when comparing two separate, unrelated groups (different people in each), not the same subjects measured twice.
  • Wilcoxon Signed-Rank Test: use instead when your paired differences are clearly not normally distributed, especially with small samples-it is the non-parametric counterpart and does not assume normality.
  • Repeated-Measures ANOVA: use instead when you have more than two related measurements (e.g., scores at week 0, 4, and 8).

Paired vs Independent vs Wilcoxon vs Repeated-Measures ANOVA

17.1 Paired t-test vs Independent t-test

AspectPaired t-testIndependent t-test
SamplesSame subjects, two conditionsTwo separate, unrelated groups
What is testedMean of the within-subject differencesDifference between two independent group means
Removes between-subject variance?Yes-this is its main advantageNo
Statistical powerGenerally higher, for the same sample sizeGenerally lower
Degrees of freedom\( n - 1 \) (n = number of pairs)\( n_1 + n_2 - 2 \) (two group sizes)

17.2 Paired t-test vs Wilcoxon Signed-Rank Test

AspectPaired t-testWilcoxon Signed-Rank Test
Data requirementDifferences approximately normalNo normality assumption on differences
What it usesRaw magnitude of the differencesRanks of the absolute differences
Statistical powerHigher, if normality genuinely holdsSlightly lower under normality, but more robust otherwise
Sensitivity to outliersHigher-outliers distort the mean directlyLower-ranking dampens the influence of extreme values

17.3 Paired t-test vs Repeated-Measures ANOVA

AspectPaired t-testRepeated-Measures ANOVA
Number of related measurementsExactly twoTwo or more (three-plus is the typical use case)
Test statistict-statisticF-statistic
RelationshipSpecial case of repeated-measures ANOVA with 2 levelsGeneralizes the paired t-test to more than 2 levels

Common Misconceptions

  • "The raw before and after scores must be normally distributed." Not quite-what must be approximately normal is the distribution of the differences, a distinct quantity from either raw sample.
  • "A significant p-value means the effect is large." No. Statistical significance and effect size are different questions-see Worked Example 1, where a real 2 kg change was not significant, and compare with Cohen's d for how to quantify magnitude separately.
  • "Paired data can just be analyzed with an independent t-test." Doing so ignores the correlation between paired observations, typically making the test overly conservative and less able to detect a real effect.
  • "The paired t-test works for any number of repeated measurements." It is strictly defined for exactly two related measurements per subject; three or more requires repeated-measures ANOVA.
  • "A non-significant result proves there is no effect." Failing to reject \( H_0 \) only means there was not enough evidence to detect an effect with this sample-it does not prove the true effect is zero.

Interview Questions

  1. Derive the paired t-test formula and explain why it is equivalent to a one-sample t-test on the differences.
  2. Why is the paired t-test generally more statistically powerful than the independent t-test for the same data?
  3. What assumption does the paired t-test make about the raw "before" and "after" scores, if any?
  4. Given a dataset with a clear outlier in the differences, how would that affect the t-statistic, and what alternative test would you consider?
  5. Explain the relationship between the paired t-test and repeated-measures ANOVA.
  6. How would you compute and interpret Cohen's d for a paired-samples design?
  7. What does a 95% confidence interval for the mean difference add beyond the p-value alone?
  8. Under what circumstances would you switch from a paired t-test to a Wilcoxon Signed-Rank Test?
  9. Why does scipy.stats.ttest_rel(after, before) require the two arrays to be the same length and in matched order?
  10. What happens to the degrees of freedom if you mistakenly treat paired data as two independent samples?

Frequently Asked Questions

  • A paired t-test is used to check whether the mean difference between two related measurements taken from the same subjects-such as a before-and-after score, or measurements on matched pairs like twins-is statistically significantly different from zero.
  • The test statistic is t = d̄ / (s_d / √n), where d̄ is the mean of the paired differences, s_d is the sample standard deviation of those differences, and n is the number of pairs. This value is compared against a t-distribution with n − 1 degrees of freedom to obtain a p-value.
  • A paired t-test compares two related measurements from the same subjects-such as before and after-and analyzes the differences within each pair, removing between-subject variability. An independent t-test compares two separate, unrelated groups of different subjects and analyzes the difference between the two group means directly.
  • The paired differences should be approximately normally distributed (especially important with small samples), the underlying data should be continuous (interval or ratio scale), the pairs should be independent of one another, and each observation must correspond to exactly one paired observation rather than three or more repeated time points.
  • If the p-value is below your chosen significance level (commonly α = 0.05), you reject the null hypothesis and conclude the mean difference between the paired measurements is statistically significant. If the p-value is at or above α, there is not enough evidence to say the observed difference reflects a real effect rather than random variation.
  • Use the Wilcoxon Signed-Rank Test, the non-parametric counterpart of the paired t-test. It works with the ranks of the paired differences instead of their raw values and does not require the differences to be normally distributed, which makes it more robust with small or skewed samples.
  • No. The paired t-test is defined for exactly two related measurements per subject. If you have three or more repeated measurements-for example scores at week 0, 4, and 8-use repeated-measures ANOVA instead, which extends the same logic to multiple time points while controlling the overall false-positive rate.
  • Because it analyzes within-subject differences, the paired t-test cancels out person-to-person variability that has nothing to do with the treatment. Each subject effectively serves as their own control, which reduces the variance the test has to work with and makes it easier to detect a real effect with the same sample size.

Key Takeaways

  • The paired t-test compares two related measurements from the same subjects by analyzing the differences between them-structurally, a one-sample t-test on those differences.
  • It is ideal for before/after, treatment/control-on-the-same-subject, or matched-pair study designs.
  • Core assumption: the differences (not the raw scores) should be approximately normally distributed.
  • In Python, scipy.stats.ttest_rel(after, before) gets you the t-statistic and p-value in one call; pair it with Cohen's d and a confidence interval for a complete picture.
  • If \( p < 0.05 \), the observed change is statistically significant; if \( p \geq 0.05 \), there isn't enough evidence of a real effect-but always check the effect size too, since the two questions are different, as both worked examples above demonstrate.
  • If your data isn't paired, or isn't normally distributed, look at the independent t-test or Wilcoxon Signed-Rank Test instead; if you have more than two related measurements, use repeated-measures ANOVA.

The paired t-test is one of the most frequently used tests in applied statistics precisely because before/after and matched-pair designs are everywhere-clinical trials, education research, UX experiments, and quality control all generate this exact data shape. Its logic is refreshingly simple: collapse two related samples into one sample of differences, then ask whether that single sample's mean is far enough from zero to rule out chance.

The two worked examples above show both sides of that logic in practice-one where a real-looking change fell short of significance with a small sample, and one where the same calculation, scaled up slightly, produced a clear and significant result. Reporting the p-value alongside the mean difference, Cohen's d, and a confidence interval, as demonstrated throughout this guide, gives a complete and honest picture that a p-value by itself cannot.