Statistics

t-Test Calculator

Run a one-sample, two-sample or paired t-test from raw data or from the mean, standard deviation and sample size. Get the t statistic, degrees of freedom, p-value, confidence interval and Cohen’s d, a plain-English conclusion, and every step of the calculation.

Set up the test

The groups can have different sizes. The test compares Group 1 − Group 2.

Paste two columns from Excel. The test uses the difference Column 2 − Column 1 (for example After − Before), so a positive mean difference means an increase.

Enter the statistics of the differences (Column 2 − Column 1).

Use the sample standard deviation (Excel STDEV.S).

Choose a test, enter your data and press Calculate, or load the example.

What this calculator does

A t-test asks whether a difference in means is larger than you would expect from random sampling alone. It turns the difference into a t statistic (the difference divided by its standard error) and compares that with the t distribution to get a p-value.

The calculator runs all three common versions, accepts raw data or summary statistics, supports one- and two-tailed alternatives, and reports the confidence interval for the difference and the effect size (Cohen’s d) alongside the p-value.

Choosing the right t-test

  • One-sample: one group against a fixed value. Does the average weight of “5 kg” atta packs really equal 5 kg?
  • Two-sample (independent): two separate groups. Do students taught by the case method score differently from those taught by lectures?
  • Paired: two measurements on the same units. Did the same 10 stores sell more after staff training than before? Pairing removes the store-to-store variation, so it detects smaller effects than a two-sample test on the same numbers.

The formulas

One-sample / paired:  t = (x̄ − μ₀) / (s / √n),  df = n − 1
Welch:  t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)
Pooled:  t = (x̄₁ − x̄₂) / (sp√(1/n₁ + 1/n₂)),  sp² = ((n₁−1)s₁² + (n₂−1)s₂²) / (n₁ + n₂ − 2)

For the paired test, x̄ and s are the mean and standard deviation of the differences. Welch’s degrees of freedom come from the Welch–Satterthwaite formula, which is why they are usually not a whole number. Cohen’s d divides the difference by the standard deviation (the pooled standard deviation for two samples, the standard deviation of the differences for paired data).

Worked example: case method vs lectures

With Two-sample selected, press Load example. It loads mock exam scores out of 100 for two PGDM sections: Section A (12 students, taught with case studies) and Section B (14 students, taught with lectures).

  • Means: Section A 75.25, Section B 66.14, a difference of 9.11 marks.
  • Welch’s t-test: t = 3.743 on 20.23 degrees of freedom, p = 0.0013. The difference is significant at α = 0.05.
  • 95% confidence interval for the difference: 4.04 to 14.18 marks.
  • Effect size: Cohen’s d = 1.51, a large effect.

Two cautions. The students were not randomly assigned to sections, so the gap may reflect who joined each section rather than the teaching method. And with groups this small, the interval is wide: the true advantage could be as small as 4 marks.

The Paired and One-sample examples load weekly sales for 10 stores before and after training, and 12 atta pack weights tested against 5 kg.

Assumptions to check

  • Independence: each observation (or each pair) is separate from the others.
  • Roughly normal data: matters for small samples (under about 30 per group). Check with the Descriptive Statistics Calculator: strong skew or extreme outliers are warning signs. For larger samples the t-test is robust.
  • Equal variances: only for the pooled test. Welch’s test does not need it, which is why it is the default here.

Getting the same result in Excel and Python

Excel’s =T.TEST(A2:A13, B2:B15, 2, 3) returns the p-value. The third argument is the number of tails (1 or 2) and the fourth is the type: 1 for paired, 2 for pooled, 3 for Welch. Excel does not return t, df or the interval directly. In Python:

from scipy import stats

section_a = [72, 68, 81, 77, 65, 79, 84, 70, 76, 74, 88, 69]
section_b = [66, 71, 59, 73, 62, 68, 64, 70, 58, 75, 61, 67, 63, 69]

res = stats.ttest_ind(section_a, section_b, equal_var=False)   # Welch
print(res.statistic, res.df, res.pvalue)    # 3.743, 20.23, 0.00126
print(res.confidence_interval())            # (4.04, 14.18)

# Paired: stats.ttest_rel(after, before)   One-sample: stats.ttest_1samp(x, 5)

Reporting the result

A standard write-up gives the test, the means, t with its degrees of freedom, the p-value, the interval and the effect size: “Section A scored higher than Section B (75.25 vs 66.14), Welch’s t(20.23) = 3.74, p = .001, 95% CI [4.04, 14.18], d = 1.51.” The Copy summary button gives you these numbers in one block.

Common mistakes

  • Running a two-sample test on paired data. It ignores the pairing, inflates the standard error and can miss a real effect.
  • Reading “not significant” as “no difference”. A small sample may simply lack the power to detect the difference. Look at the confidence interval.
  • Running many t-tests to compare three or more groups. Each extra test raises the chance of a false positive. Use one-way ANOVA instead.

Related learning on Codeayan

FAQ

t-test questions

Which t-test should I use?

Use a one-sample t-test to compare one group's mean with a fixed target, such as a pack weight of 5 kg. Use a two-sample (independent) t-test to compare the means of two separate groups, such as two classes. Use a paired t-test when each value in one column belongs with a value in the other, such as the same stores before and after a change.

Should I use Welch's t-test or Student's pooled t-test?

Use Welch's test by default. It does not assume the two groups have the same variance, and when the variances happen to be equal it gives almost the same answer as the pooled test. The pooled test can give misleading p-values when the variances and group sizes both differ.

One-tailed or two-tailed?

Use two-tailed unless you decided before seeing the data that only one direction matters and you would treat a result in the other direction exactly like no difference. Switching to one-tailed after looking at the data halves the p-value and is a common way results get overstated.

What does Cohen's d tell me that the p-value does not?

The p-value tells you whether a difference is likely to be real; Cohen's d tells you how big it is in standard deviation units. As a rough guide, 0.2 is small, 0.5 medium and 0.8 large. With a large sample, a tiny and unimportant difference can still have a very small p-value.

Can I run a t-test with only the mean, standard deviation and sample size?

Yes. Switch the input to "Summary statistics" and enter the mean, standard deviation and n for each group. This is how most exam questions are set, and it gives exactly the same result as entering the raw data.

More tools

Keep going