T-Test Calculator

Run a one-sample, two-sample, or paired t-test directly from raw data. Enter your values below, and see the formula, worked examples, and ready-to-use Python code underneath.

Enter your data

Separate values with commas, spaces, or new lines.

Please check your inputs.

T-statistic
Degrees of freedom
P-value
Decision at chosen α

What a t-test tells you

A t-test checks whether an observed difference in means is likely to be real, or could plausibly be explained by random sampling variation. It's the standard tool for comparing means when the population standard deviation isn't known and has to be estimated from the sample itself — which describes most real-world data.

There are three common variants, all supported by this calculator:

  • One-sample — compares a sample's mean to a fixed, hypothesized value.
  • Two-sample (independent) — compares the means of two separate groups.
  • Paired — compares two measurements taken from the same subjects, such as before-and-after values.

T-test formulas

One-sample & paired:  t = ( x̄ − μ₀ ) / ( s / √n ),  df = n − 1

Two-sample (Welch's, unequal variances):
t = ( x̄₁ − x̄₂ ) / √( s₁²/n₁ + s₂²/n₂ )
x̄ is the sample mean, μ₀ is the hypothesized mean, s is the sample standard deviation, and n is the sample size. For the paired test, the "sample" is the list of paired differences. Welch's degrees of freedom are estimated with the Welch–Satterthwaite equation rather than a simple n₁ + n₂ − 2, which is why the value shown often isn't a whole number.

Python code

SciPy covers all three variants directly:

# One-sample t-test
from scipy import stats
data = [102, 98, 105, 101, 97, 103, 99, 104]
t_stat, p_value = stats.ttest_1samp(data, popmean=100)

# Two-sample t-test (Welch's — unequal variances)
group_a = [23, 25, 21, 19, 24]
group_b = [30, 28, 32, 27, 29]
t_stat, p_value = stats.ttest_ind(group_a, group_b, equal_var=False)

# Paired t-test
before = [70, 72, 68, 75, 71]
after  = [68, 70, 67, 73, 69]
t_stat, p_value = stats.ttest_rel(before, after)

Worked example — one-sample

A cereal box is labeled as containing 100g. A sample of 8 boxes weighs 102, 98, 105, 101, 97, 103, 99, and 104 grams. Is the true average weight different from 100g (two-tailed, α = 0.05)?

  1. 1
    Compute the sample mean and standard deviation.
    x̄ = 101.125g, s = 2.9001g, n = 8
  2. 2
    Compute the standard error and t-statistic.
    SE = 2.9001 / √8 = 1.0253  →  t = (101.125 − 100) / 1.0253 = 1.0972
  3. 3
    Find the two-tailed p-value with df = 7.
    p = 0.3089
  4. 4
    Compare to α.
    0.3089 > 0.05, so we fail to reject the null hypothesis.

There's no statistically significant evidence, at α = 0.05, that the true average box weight differs from 100g.

Frequently asked questions

When should I use a t-test instead of a z-test?

Use a t-test when the population standard deviation is unknown and must be estimated from the sample, which is the case in most real studies. Use a z-test only when the population standard deviation is genuinely known in advance.

What's the difference between a two-sample and a paired t-test?

A two-sample (independent) t-test compares the means of two separate, unrelated groups, such as a treatment group and a control group made up of different people. A paired t-test compares two measurements taken from the same subjects, such as before-and-after scores, and analyzes the differences directly, which removes person-to-person variation from the comparison.

Why does this calculator use Welch's t-test by default for two samples?

Welch's t-test doesn't assume the two groups have equal variances, unlike the classic pooled-variance (Student's) t-test. Because it performs about as well when variances are equal and considerably better when they aren't, most modern statistical software, including R, uses Welch's version as the default.

Why is the degrees of freedom for Welch's t-test not a whole number?

Welch's test estimates degrees of freedom with the Welch–Satterthwaite equation, which blends the two samples' variances and sizes into a single value that typically isn't an integer. This is expected and doesn't need to be rounded for the p-value calculation.

How large does my sample need to be for a t-test?

There's no strict minimum, but t-tests are most reliable when the underlying data is roughly normally distributed, or when the sample is large enough (often cited as n ≥ 30) for the sampling distribution of the mean to be approximately normal regardless of the data's own shape.

Advertisement