Two-sample t-test calculator (Welch)

By Jude Wallis · Published

A two-sample (independent) t-test checks whether two population means differ. Enter each group's mean, standard deviation, and sample size to get the standard error, the t statistic, the Welch degrees of freedom, and a p-value.

two-sample t-test (Welch df = 59.91)

t = 2.1576, p = 0.035

At alpha = 0.05: reject the null hypothesis. Assumes two independent samples (for paired data, use the one-sample test on differences).

Steps

  1. 1.difference = 78.2 - 74.5 = 3.7
  2. 2.SE = sqrt(s1²/n1 + s2²/n2) = sqrt(1.3653 + 1.5753) = 1.71483
  3. 3.t = 3.7 / 1.71483 = 2.1576
  4. 4.df (Welch-Satterthwaite, the software formula) = 59.91
  5. 5.p-value = 0.035

AP Statistics: Unit 4 (topics 4.9 Setting Up a Test for the Difference Between Two Population Means, 4.10 Carrying Out a Test for the Difference Between Two Population Means). This is the hypothesis-test half of Unit 4, topics 4.9 and 4.10, in the Fall 2026 AP Statistics course, where the exam expects you to find the degrees of freedom and p-value with technology.

What a two-sample t-test compares

A two-sample t-test compares the means of two independent groups to decide whether the underlying population means differ. Independent means the two samples come from separate groups, with no pairing between an observation in one group and an observation in the other.

You work with six numbers: the two sample means xˉ1\bar{x}_1 and xˉ2\bar{x}_2 (the average of each group), the two sample standard deviations s1s_1 and s2s_2 (how spread out each group is), and the two sample sizes n1n_1 and n2n_2. The test asks about the population means μ1\mu_1 and μ2\mu_2, which you cannot observe directly.

This two sample t test calculator (also called an independent t test calculator) takes those six numbers and returns the standard error, the t statistic, the degrees of freedom, and a p-value. If your two measurements come from the same subjects, such as before and after, you want a paired t-test instead of this one.

The standard error and test statistic

The standard error (SE) measures how much the difference in sample means, xˉ1xˉ2\bar{x}_1 - \bar{x}_2, would bounce around from sample to sample. The AP formula sheet gives it as

SE=s12n1+s22n2SE = \sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}

Each group contributes its own variance divided by its own sample size, and the two pieces add under the square root. The sheet lists only this unpooled version for means, so there is no pooled two-sample formula for means to memorize.

The standardized test statistic follows the same template as every AP test, (statistic - parameter) divided by (standard error):

t=(xˉ1xˉ2)(μ1μ2)s12n1+s22n2t = \frac{(\bar{x}_1 - \bar{x}_2) - (\mu_1 - \mu_2)}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}

Under the null hypothesis the difference μ1μ2\mu_1 - \mu_2 equals 0, so the top reduces to xˉ1xˉ2\bar{x}_1 - \bar{x}_2. A t value far from 0 is evidence that the population means are not equal.

Degrees of freedom for a two-sample t-test

Degrees of freedom (df) set the shape of the t-distribution you compare your t value against. For a two-sample t-test the df is usually not a whole number and is not simply n1+n22n_1 + n_2 - 2.

Software computes it with the Welch-Satterthwaite formula:

df=(s12n1+s22n2)21n11(s12n1)2+1n21(s22n2)2df = \frac{\left(\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}\right)^2}{\frac{1}{n_1 - 1}\left(\frac{s_1^2}{n_1}\right)^2 + \frac{1}{n_2 - 1}\left(\frac{s_2^2}{n_2}\right)^2}

You are not asked to compute this by hand on the AP exam. The College Board states only that the df falls between the smaller of n11n_1 - 1 and n21n_2 - 1 at the low end and n1+n22n_1 + n_2 - 2 at the high end, and that you find the exact value with technology. The Welch df is smaller than n1+n22n_1 + n_2 - 2, which makes the test a little more cautious.

By hand, without a calculator, you can use the conservative choice: df = the smaller of n11n_1 - 1 and n21n_2 - 1. That gives a larger p-value than the Welch df, so it never overstates your evidence.

Hypotheses and conditions

State the hypotheses about the population means. The null says the means are equal:

H0:μ1μ2=0H_0: \mu_1 - \mu_2 = 0

The alternative is two-sided when you only ask whether they differ, or one-sided when you have a direction:

Ha:μ1μ20orμ1μ2<0orμ1μ2>0H_a: \mu_1 - \mu_2 \neq 0 \quad \text{or} \quad \mu_1 - \mu_2 < 0 \quad \text{or} \quad \mu_1 - \mu_2 > 0

Check three conditions before you trust the result:

  • Random: the data come from two independent random samples or a randomized experiment.
  • 10%: when sampling without replacement, each sample is at most 10% of its population. This is not needed for a randomized experiment.
  • Normal or large: each sample size is at least 30, or each population is stated to be approximately normal. If either sample is under 30, both sets of sample data should be free of strong skewness and outliers.

How to use this calculator

Enter the sample mean, sample standard deviation, and sample size for each group, then pick a one-sided or two-sided alternative. The calculator returns:

  • the standard error from the formula above,
  • the t statistic,
  • the Welch degrees of freedom,
  • the p-value.

Compare the p-value to your significance level, often 0.05. A p-value below the level is evidence against H0H_0, so you reject it and conclude the population means differ. A p-value above the level means you fail to reject H0H_0, so the data are consistent with equal means. The worked example below runs every number by hand so you can check the tool digit by digit.

Comparing two fertilizers on plant height

A gardener grows tomato plants under two fertilizers. The 10 plants on fertilizer A have a mean height of 85 cm with a sample standard deviation of 8 cm. The 20 plants on fertilizer B have a mean height of 82 cm with a sample standard deviation of 3 cm. Plants were randomly assigned to the fertilizers. Test at the 0.05 level whether the mean heights differ. Let group 1 be fertilizer A (xˉ1=85\bar{x}_1 = 85, s1=8s_1 = 8, n1=10n_1 = 10) and group 2 be fertilizer B (xˉ2=82\bar{x}_2 = 82, s2=3s_2 = 3, n2=20n_2 = 20).

  1. State the hypotheses. H0:μ1μ2=0H_0: \mu_1 - \mu_2 = 0 and Ha:μ1μ20H_a: \mu_1 - \mu_2 \neq 0, where μ1\mu_1 and μ2\mu_2 are the mean heights under fertilizers A and B.

  2. Check conditions. The plants were randomly assigned, so this is a randomized experiment: the random condition holds and the 10% condition is not needed. Both samples are under 30, so assume both height distributions are approximately normal.

  3. Compute each variance term. s12n1=8210=6410=6.4\frac{s_1^2}{n_1} = \frac{8^2}{10} = \frac{64}{10} = 6.4 and s22n2=3220=920=0.45\frac{s_2^2}{n_2} = \frac{3^2}{20} = \frac{9}{20} = 0.45.

  4. Find the standard error. SE=6.4+0.45=6.85=2.6173SE = \sqrt{6.4 + 0.45} = \sqrt{6.85} = 2.6173 cm.

  5. Compute the t statistic. The difference in sample means is 8582=385 - 82 = 3 cm, so t=302.6173=1.146t = \frac{3 - 0}{2.6173} = 1.146.

  6. Find the degrees of freedom. Welch-Satterthwaite gives df=(6.85)26.429+0.45219=46.92254.5511+0.0107=46.92254.5618=10.29df = \frac{(6.85)^2}{\frac{6.4^2}{9} + \frac{0.45^2}{19}} = \frac{46.9225}{4.5511 + 0.0107} = \frac{46.9225}{4.5618} = 10.29. This is well below n1+n22=28n_1 + n_2 - 2 = 28.

  7. Find the p-value. For a two-sided test with t=1.146t = 1.146 and df10.29df \approx 10.29, software reports p0.28p \approx 0.28.

  8. Decide. Since p0.28>0.05p \approx 0.28 > 0.05, you fail to reject H0H_0.

SE=2.6173SE = 2.6173 cm, t=1.146t = 1.146, Welch df10.29df \approx 10.29, and two-sided p0.28p \approx 0.28. Because p>0.05p > 0.05, there is not enough evidence to conclude the mean tomato-plant heights differ between the two fertilizers.

Frequently asked questions

Should I use a pooled or Welch two-sample t-test?

Use the Welch (unpooled) version, which is what this calculator and the AP formula sheet use. It does not assume the two populations have equal variances, so it stays valid when the group spreads differ. Most statistical software defaults to Welch for the same reason.

Why is the degrees of freedom a decimal like 10.29?

The Welch-Satterthwaite formula that software uses produces a non-integer df, and the software applies it directly to find the p-value. The AP course only asks you to know that the df falls between the smaller of n11n_1 - 1 and n21n_2 - 1 and n1+n22n_1 + n_2 - 2, with technology giving the exact value.

Is a two-sample t-test the same as a paired t-test?

No. A two-sample t-test compares two independent groups. A paired t-test is for dependent data, such as before-and-after measurements on the same subjects, and it analyzes the single set of differences with a one-sample t procedure.