What is the Two Sample t-test: Definition, Formula, and Example?

The Two Sample t-test is a statistical test used to compare the means of two independent samples. It is used to determine if there is a statistically significant difference between the two sets of data. The formula for the Two Sample t-test is t = (x1 – x2) / (s1^2 + s2^2)^1/2, where x1 is the mean of the first sample, x2 is the mean of the second sample, s1 is the standard deviation of the first sample, and s2 is the standard deviation of the second sample. An example of a Two Sample t-test would be to compare the mean heights of two different groups of adults.


A two sample t-test is used to determine whether or not two are equal.

This tutorial explains the following:

  • The motivation for performing a two sample t-test.
  • The formula to perform a two sample t-test.
  • The assumptions that should be met to perform a two sample t-test.
  • An example of how to perform a two sample t-test.

Two Sample t-test: Motivation

Suppose we want to know whether or not the mean weight between two different species of turtles is equal. Since there are thousands of turtles in each population, it would be too time-consuming and costly to go around and weigh each individual turtle.

Instead, we might take a simple random sample of 15 turtles from each population and use the mean weight in each sample to determine if the mean weight is equal between the two populations:

Two sample t-test example

However, it’s virtually guaranteed that the mean weight between the two samples will be at least a little different. The question is whether or not this difference is statistically significant. Fortunately, a two sample t-test allows us to answer this question.

Two Sample t-test: Formula

A two-sample t-test always uses the following null hypothesis:

  • H0: μ1 = μ2 (the two population means are equal)

The alternative hypothesis can be either two-tailed, left-tailed, or right-tailed:

  • H1 (two-tailed): μ1 ≠ μ2 (the two population means are not equal)
  • H1 (left-tailed): μ1 < μ2 (population 1 mean is less than population 2 mean)
  • H1 (right-tailed): μ1> μ2 (population 1 mean is greater than population 2 mean)

We use the following formula to calculate the test statistic t:

Test statistic: (x1 – x2)  /  sp(√1/n1 + 1/n2)

where x1 and x2 are the sample means, n1 and nare the sample sizes, and where sp is calculated as:

sp = √ (n1-1)s12 +  (n2-1)s22 /  (n1+n2-2)

If the p-value that corresponds to the test statistic t with (n1+n2-1) degrees of freedom is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.

Two Sample t-test: Assumptions

For the results of a two sample t-test to be valid, the following assumptions should be met:

  • The observations in one sample should be independent of the observations in the other sample.
  • The data should be approximately normally distributed.
  • The two samples should have approximately the same variance. If this assumption is not met, you should instead perform Welch’s t-test.
  • The data in both samples was obtained using a .

Two Sample t-test: Example

Suppose we want to know whether or not the mean weight between two different species of turtles is equal. To test this, will perform a two sample t-test at significance level α = 0.05 using the following steps:

Step 1: Gather the sample data.

Suppose we collect a random sample of turtles from each population with the following information:

Sample 1:

  • Sample size n1 = 40
  • Sample mean weight x1 = 300
  • Sample standard deviation s1 = 18.5

Sample 2:

  • Sample size n2 = 38
  • Sample mean weight x2 = 305
  • Sample standard deviation s2 = 16.7

Step 2: Define the hypotheses.

We will perform the two sample t-test with the following hypotheses:

  • H0μ1 = μ2 (the two population means are equal)
  • H1μ1 ≠ μ2 (the two population means are not equal)

Step 3: Calculate the test statistic t.

First, we will calculate the pooled standard deviation sp:

sp = √ (n1-1)s12 +  (n2-1)s22 /  (n1+n2-2) = √ (40-1)18.52 +  (38-1)16.72 /  (40+38-2) = 17.647

Next, we will calculate the test statistic t:

t = (x1 – x2)  /  sp(√1/n1 + 1/n2) =  (300-305) / 17.647(√1/40 + 1/38) = -1.2508

Step 4: Calculate the p-value of the test statistic t.

According to the T Score to P Value Calculator, the p-value associated with t = -1.2508 and degrees of freedom = n1+n2-2 = 40+38-2 = 76 is 0.21484.

Step 5: Draw a conclusion.

Since this p-value is not less than our significance level α = 0.05, we fail to reject the null hypothesis. We do not have sufficient evidence to say that the mean weight of turtles between these two populations is different.

Note: You can also perform this entire two sample t-test by simply using the Two Sample t-test Calculator.

The following tutorials explain how to perform a two-sample t-test using different statistical programs:

How to Perform a Two Sample t-test in Excel
How to Perform a Two Sample t-test in SPSS
How to Perform a Two Sample t-test in Stata

How to Perform a Two Sample t-test in Python
How to Perform a Two Sample t-test on a TI-84 Calculator

x