To do a t-test, pick the right type (one-sample, independent-samples or paired), state your hypotheses, check the assumptions, compute t = difference ÷ standard error, find the p-value from the t-distribution with the correct degrees of freedom, compare it to your significance level, and report the difference with a confidence interval and effect size. This guide is part of our Statistics series. It works three small examples by hand, then repeats them in Excel, Google Sheets, R and Python so you can check every number.
Last reviewed: November 28, 2026. All data in this article is illustrative.
| Your data | Test | Worked in |
|---|---|---|
| One group and a target value | One-sample t-test | Example 3 |
| Two separate groups | Welch's t-test | Example 1 |
| Two separate groups, equal variances justified | Student's t-test | Example 1 |
| Same subjects measured twice | Paired-samples t-test | Example 2 |
Which T-Test Should You Use?
Use a one-sample t-test to compare one group with a fixed value, an independent-samples t-test (also called a two-sample t-test) for two separate groups, and a paired-samples t-test when the same subjects are measured twice. For two separate groups, default to Welch's t-test.
- One group and a target? Compare its mean with a fixed value, such as a 50 g specification: one-sample.
- Two groups, different subjects in each? Compare two means: independent-samples.
- Two measurements on the same subjects? Before and after, or matched pairs: paired-samples.
| Test | Use when | df | Excel type |
|---|---|---|---|
| One-sample | One group against a value | n − 1 | none |
| Welch's | Two independent groups | Welch–Satterthwaite | 3 |
| Student's | Two independent groups, equal variances | n₁ + n₂ − 2 | 2 |
| Paired | Same subjects twice | n − 1 (pairs) | 1 |
Independent groups have two versions. Student's t-test pools the variances into one estimate and assumes they are equal. Welch's t-test keeps them separate and adjusts the degrees of freedom. When the variances match, Welch gives nearly the same answer; when they differ, it keeps the false-positive rate near the level you chose and Student's does not. Delacre, Lakens and Leys (2017) argue for Welch as the default, and R's t.test already works that way.
Skip the preliminary test of equal variances. Letting its result pick between the two versions often fails to give an appropriate answer, as the same paper shows. With three or more groups, use ANOVA instead of a pile of t-tests.
How to Do a T-Test: 7 Steps
Here is how to do a t-test in seven steps. The formulas use Welch's version for two groups.
Step 1: State the hypotheses
Write the null hypothesis (no difference) and the alternative hypothesis before you look at the results. For two groups, H0: μ1 = μ2 against H1: μ1 ≠ μ2, with μ for the population means. Set the significance level (alpha, α), usually 0.05, and choose one-tailed or two-tailed. Two-tailed is the default.
Common mistake: picking the tail after seeing the data. In the predicted direction the one-tailed p-value is half the two-tailed one, so a late switch quietly halves your p-value.
Step 2: Choose the t-test type and confirm the data fit it
Match the design to a test, then check the layout. Paired data needs one row per subject holding both values, and independent groups must share no subjects.
Common mistake: running an independent test on paired data. Example 2 shows the cost.
Step 3: Check the assumptions
Summarize each group with the descriptive statistics calculator (how to read summary statistics explains the output). Then plot the data: a histogram maker or box plot maker shows skew, gaps and outliers in seconds.
Common mistake: skipping the plot. A typo such as 1500 for 150 can flip a result.
Step 4: Compute the t-statistic
Divide the observed difference by its standard error (SE). Here x̄ is the sample mean, s the sample standard deviation (standard deviation explained covers the idea), n the sample size and μ0 the value in the null hypothesis.
One-sample: t = (x̄ − μ0) / (s / √n)
Two groups (Welch): t = (x̄1 − x̄2) / √(s12/n1 + s22/n2)
Paired: di = beforei − afteri, then t = d̄ / (sd / √n)
The statistic counts the standard errors between the difference and zero. A paired test is a one-sample test on the differences, so pairing removes variation between subjects.
Common mistake: dividing by s where the formula calls for s / √n.
Step 5: Find the degrees of freedom and the p-value
One-sample and paired tests use df = n − 1 (n counts pairs). Student's pooled test uses n1 + n2 − 2. Welch's uses the Welch–Satterthwaite formula, usually a non-integer:
df = (s12/n1 + s22/n2)2 / [ (s12/n1)2/(n1 − 1) + (s22/n2)2/(n2 − 1) ]
The two-tailed p-value is the area of the t-distribution beyond ±|t| at that df: the probability, assuming the null hypothesis is true, of a result at least as extreme as yours.
Common mistake: reading p as the probability that the null hypothesis is true.
Step 6: Make the decision
If p ≤ α, reject the null hypothesis; otherwise, fail to reject it. Comparing |t| with the critical value for your df gives the same answer. Never write "accept the null." A non-significant result means the data did not rule out zero, so check the step 7 interval for the sizes that remain plausible.
Common mistake: treating "fail to reject" as proof of no effect.
Step 7: Report the difference, its confidence interval and an effect size
The 95% confidence interval for a difference is the estimate ± tcrit × SE, with the test's df. Cohen's d divides the difference in means by the pooled standard deviation sp; for paired data, dz divides the mean difference by the standard deviation of the differences. Hedges' g adds a small-sample correction. Cohen's 0.2, 0.5 and 0.8 are rough conventions, and context matters.
sp = √[ ((n1 − 1)s12 + (n2 − 1)s22) / (n1 + n2 − 2) ] d = (x̄1 − x̄2) / sp dz = d̄ / sd
Common mistake: reporting "p < 0.05" and nothing else.
Worked Example 1: Independent-Samples T-Test (Welch)
The new onboarding flow is about four minutes faster, and Welch's t-test says a gap that size is unlikely to be chance (t = −4.733, p = 0.000329).
Question and data. Does a redesigned onboarding flow change the time users need to finish setup? Minutes to finish, eight users per flow:
| Flow | Minutes | Mean | SD |
|---|---|---|---|
| New | 12, 15, 11, 14, 13, 16, 12, 15 | 13.50 | 1.773 |
| Old | 18, 16, 17, 19, 15, 20, 17, 18 | 17.50 | 1.604 |
Hypotheses. H0: μnew = μold. H1: μnew ≠ μold. α = 0.05, two-tailed, and every difference is new − old.
Calculation. The sample variances are s12 = 3.143 and s22 = 2.571.
SE = √(3.143/8 + 2.571/8) = √0.7143 = 0.8452
t = (13.50 − 17.50) / 0.8452 = −4.733
df = 0.71432 / (0.39292/7 + 0.32142/7) = 13.86
Result. The two-tailed p-value is 0.000329. The 95% confidence interval is −4.00 ± 2.147 × 0.8452, or −5.81 to −2.19 minutes. The pooled standard deviation is 1.690, so Cohen's d = −4.00 / 1.690 = −2.37.
Student's pooled version gives the same t = −4.733 with df = 14 and p = 0.000321. The two agree because the groups have equal sizes and similar variances; Welch pulls ahead when variances differ.
Interpretation. The new flow is about four minutes faster on average and the interval excludes zero, so we reject the null hypothesis at α = 0.05. A d of −2.37 is very large, but eight users per group is a tiny, idealized sample, and real effects are rarely this clean.
Worked Example 2: Paired-Samples T-Test (and What Goes Wrong with the Wrong Test)
Run as a paired test, these readings give t = 5.158 and p = 0.00131. Run as an independent test, the same numbers give p = 0.189.
Question. Did systolic blood pressure change after an exercise program in the same eight patients? The readings are illustrative, not clinical advice.
| Patient | Before | After | Difference |
|---|---|---|---|
| 1 | 142 | 135 | 7 |
| 2 | 150 | 148 | 2 |
| 3 | 138 | 134 | 4 |
| 4 | 155 | 149 | 6 |
| 5 | 147 | 146 | 1 |
| 6 | 160 | 151 | 9 |
| 7 | 144 | 140 | 4 |
| 8 | 152 | 147 | 5 |
Hypotheses. H0: the mean difference is 0. H1: it is not 0. α = 0.05, two-tailed, with each difference taken as before − after.
Calculation. The mean difference is d̄ = 4.75 and the standard deviation of the differences is sd = 2.605.
SE = 2.605 / √8 = 0.921
t = 4.75 / 0.921 = 5.158, df = 7
Result. The two-tailed p-value is 0.00131. With tcrit = 2.365, the 95% confidence interval for the mean reduction is 4.75 ± 2.365 × 0.921, or 2.57 to 6.93 mmHg. The effect size is dz = 4.75 / 2.605 = 1.82.
The wrong test. Now treat the two columns as independent groups. The mean difference is still 4.75 mmHg, but the standard error jumps from 0.921 to 3.44, because the spread between patients (SD 7.21 before, 6.54 after) now counts as noise. The result is t = 1.380, df = 13.87, p = 0.189, not significant.
Why it happens. Patients differ from each other by up to 22 mmHg (138 to 160), yet each one dropped by 1 to 9. The paired test works on the within-person changes. The independent test cannot separate them from the between-person spread, so a real, consistent drop gets buried.
Worked Example 3: One-Sample T-Test
The sample mean is 51.5 g, but with ten widgets that is not enough to say the true mean differs from the 50 g specification (t = 1.567, p = 0.1516).
Question and data. Does the mean widget weight differ from the 50 g specification? Ten weights in grams: 48, 52, 47, 55, 50, 53, 49, 56, 51, 54.
Hypotheses. H0: μ = 50. H1: μ ≠ 50. α = 0.05, two-tailed.
Calculation. The sample gives x̄ = 51.5 and s = 3.028.
SE = 3.028 / √10 = 0.9575
t = (51.5 − 50) / 0.9575 = 1.567, df = 9
Result. The two-tailed p-value is 0.1516. With tcrit = 2.262, the 95% confidence interval is 51.5 ± 2.262 × 0.9575, or 49.33 to 53.67 g.
Interpretation. We fail to reject the null hypothesis. The interval includes 50, so the summary is "no evidence the mean differs from 50 g," not "the mean is 50 g." The interval runs from 0.67 g under spec to 3.67 g over, so ten widgets cannot settle the question.
To check your arithmetic, paste any example's values into the t-test calculator.
How to Do a T-Test in Excel and Google Sheets
In Excel, =T.TEST(array1, array2, tails, type) returns the p-value for a two-sample or paired test. It does not return t or the degrees of freedom. For those, use the Analysis ToolPak or the formulas from step 4.
| Argument | Meaning | Values |
|---|---|---|
| array1, array2 | The two data ranges | Same size for paired |
| tails | One- or two-tailed p-value | 1 or 2 |
| type | Which test to run | 1 paired, 2 equal variance (Student's), 3 unequal variance (Welch's) |
How to do a t-test with T.TEST
Layout: new-flow times in A2:A9, old-flow in B2:B9, before in C2:C9, after in D2:D9 and widget weights in E2:E11, with headers in row 1.
=T.TEST(A2:A9,B2:B9,2,3) → 0.000329 (Example 1, Welch, two-tailed)
=T.TEST(C2:C9,D2:D9,2,1) → 0.00131 (Example 2, paired, two-tailed)
Excel has no one-sample version of T.TEST, so build it from the step 4 and step 5 formulas. Put the t-statistic in G1, then ask for its p-value:
G1: =(AVERAGE(E2:E11)-50)/(STDEV.S(E2:E11)/SQRT(COUNT(E2:E11))) → 1.567
G2: =T.DIST.2T(ABS(G1),COUNT(E2:E11)-1) → 0.1516
Data Analysis ToolPak
If Data Analysis is missing from the Data tab, load the Analysis ToolPak add-in first. Its three t-test tools are paired two sample for means, two-sample assuming equal variances, and two-sample assuming unequal variances (Welch's). The output includes t Stat, df, the p-values and the critical values. There is no one-sample tool, so the formulas above still apply. For wider spreadsheet workflows, see data analysis in Excel.
How to do a t-test in Google Sheets
Sheets takes the same arguments, T.TEST(range1, range2, tails, type), and also accepts TTEST. Google's help page says both ranges must have the same number of data points, so unequal group sizes need another tool.
How to Do a T-Test in R and Python
Each example takes one call in either language. R's t.test is Welch's version by default; in SciPy, set equal_var=False.
How to do a t-test in R
new <- c(12, 15, 11, 14, 13, 16, 12, 15)
old <- c(18, 16, 17, 19, 15, 20, 17, 18)
before <- c(142, 150, 138, 155, 147, 160, 144, 152)
after <- c(135, 148, 134, 149, 146, 151, 140, 147)
weights <- c(48, 52, 47, 55, 50, 53, 49, 56, 51, 54)
t.test(new, old) # Example 1, Welch: t = -4.733, df = 13.86, p = 0.000329
t.test(new, old, var.equal = TRUE) # Student's: df = 14, p = 0.000321
t.test(before, after, paired = TRUE) # Example 2: t = 5.158, df = 7, p = 0.00131
t.test(weights, mu = 50) # Example 3: t = 1.567, df = 9, p = 0.1516
How to do a t-test in Python
from scipy import stats
new = [12, 15, 11, 14, 13, 16, 12, 15]
old = [18, 16, 17, 19, 15, 20, 17, 18]
before = [142, 150, 138, 155, 147, 160, 144, 152]
after = [135, 148, 134, 149, 146, 151, 140, 147]
weights = [48, 52, 47, 55, 50, 53, 49, 56, 51, 54]
a = stats.ttest_ind(new, old, equal_var=False) # Example 1, Welch
print(a.statistic, a.pvalue, a.df) # -4.733 0.000329 13.86
print(a.confidence_interval()) # 95% CI for new - old: -5.81 to -2.19
b = stats.ttest_rel(before, after) # Example 2, paired
print(b.statistic, b.pvalue, b.df) # 5.158 0.00131 7
print(b.confidence_interval()) # 95% CI for before - after: 2.57 to 6.93
c = stats.ttest_1samp(weights, 50) # Example 3
print(c.statistic, c.pvalue, c.df) # 1.567 0.1516 9
print(c.confidence_interval()) # 95% CI for the mean: 49.33 to 53.67
These calls ran on Python 3.13 with SciPy 1.18.1. The .df attribute and .confidence_interval() method need SciPy 1.11 or newer for ttest_ind and 1.10 or newer for the other two.
Doing a T-Test with the Amridata T-Test Calculator
If you would rather skip the arithmetic, run it in the calculator. Paste values from a spreadsheet column or type them separated by commas, without thousands separators. Or enter each group's mean, standard deviation and sample size. Choose one-sample, two-sample (Welch's, the default), two-sample (Student's) or paired, then set α and the tail direction. The output lists t, df, p, the mean difference with a confidence interval, and Cohen's d. It is a convenience, and assumption checks stay your job.
T-Test Assumptions and What to Do When They Fail
A t-test needs independent observations, an interval or ratio outcome, and a roughly normal sampling distribution of the mean. Student's version also needs equal variances, one more reason to prefer Welch's.
- Independence. Observations must not influence each other, within or between groups. Designed pairing is the one exception, and the paired test handles it. Repeated readings on one person, entered as separate people, break the rule.
- Scale. Measure the outcome on an interval or ratio scale, such as minutes or grams.
- Normality. The normality assumption concerns the sampling distribution of the mean. In small samples that means roughly normal data, or differences for a paired test. With moderate to large samples the test is fairly robust (central limit theorem) unless skew or outliers are extreme. A mean far from the median hints at skew; see mean, median and mode and histogram shapes.
- Outliers. Screen with the outlier calculator; how to find outliers has the rules. Remove a point only when it is a documented error, such as a wrong unit, never because it is inconvenient. Tidy blanks and stray text first with the CSV data cleaner.
- Equal variances. Only Student's test needs them. Use Welch's.
If a small sample is heavily skewed, try a transformation such as the log, or switch to a rank-based test: the Mann–Whitney U test for independent groups or the Wilcoxon signed-rank test for paired data. Both answer a slightly different question, since neither is strictly a test of means. Explore first, as in these exploratory data analysis steps.
A note for A/B testing. A two-sample t-test on means suits continuous metrics such as revenue per user. Conversion rates are proportions, and a different test is usually standard for those.
How to Read and Report T-Test Results
Reporting is the last part of how to do a t-test. Read a result in this order: difference, interval, p, effect size. The table decodes Example 1.
| Output | Value | Meaning |
|---|---|---|
| t | −4.73 | Difference in standard errors |
| df | 13.86 | Welch-adjusted degrees of freedom |
| p | 0.000329 | Chance of a t this extreme if H0 were true |
| 95% CI | −5.81 to −2.19 | Plausible range for new − old |
| Cohen's d | −2.37 | Difference in pooled SD units |
Onboarding took less time with the new flow (M = 13.50, SD = 1.77, n = 8) than with the old flow (M = 17.50, SD = 1.60, n = 8), Welch's t(13.86) = −4.73, p < .001, mean difference = −4.00 minutes, 95% CI [−5.81, −2.19], d = −2.37.
Systolic pressure fell by 4.75 mmHg on average after the program (SD of differences = 2.60, n = 8), paired t(7) = 5.16, p = .001, 95% CI [2.57, 6.93], dz = 1.82.
A difference in means does not show cause on its own; see correlation vs causation.
Common T-Test Mistakes
Most errors in how to do a t-test trace back to a few habits.
- Using an independent test on paired data. Example 2 went from p = 0.00131 to p = 0.189.
- Choosing the tail after the fact. Decide before you see the data.
- Running many t-tests on three or more groups. Each adds false-positive risk. Use ANOVA.
- Writing "accept the null." Say "fail to reject," and read the interval.
- Reporting p alone. Add the difference, the confidence interval and an effect size.
- Gatekeeping with a variance test. Use Welch's and skip the preliminary test.
- Deleting inconvenient outliers. Remove documented errors only.
- Confusing significant with important. A tiny p-value can sit beside a trivial difference.
Frequently Asked Questions
What is the first step in doing a t-test?
State your hypotheses and choose the test type. Write the null hypothesis (no difference) and the alternative, set your significance level, usually 0.05, and choose one-tailed or two-tailed before seeing the data. Then match the design to a test: one group, two groups, or paired measurements.
How do I know which t-test to use?
Ask how the data were collected. One group against a fixed value calls for a one-sample t-test. Two separate groups call for an independent-samples test, with Welch's version as the safe default. The same subjects measured twice call for a paired-samples test. Three or more groups need ANOVA.
How do you do a t-test in Excel?
Enter each group in its own column and use =T.TEST(array1, array2, tails, type). Set tails to 2 for two-tailed, and type to 1 for paired, 2 for equal variances or 3 for unequal variances (Welch). It returns only the p-value; the Analysis ToolPak also reports t and df.
What is a good p-value for a t-test?
There is no good or bad p-value. Compare it with the significance level you chose before the test, usually 0.05, and reject the null hypothesis if p is at or below it. The p-value is not the probability that the null is true, so report the confidence interval too.
Can I do a t-test with a small sample size?
Yes. The t-test was built for small samples, though statistical power is low and the confidence interval will be wide. Plot the data first, since the normality assumption matters more with few observations. Treat a non-significant result as inconclusive, not as proof of no difference.
What is the difference between a paired and an independent t-test?
A paired t-test compares two measurements on the same subjects, such as before and after, by running a one-sample test on each subject's difference. An independent t-test compares two separate groups. Pairing removes variation between subjects, so it can detect small consistent changes an independent test would miss.
What if my data are not normally distributed?
With moderate or large samples, the t-test is fairly robust unless the data are heavily skewed or have extreme outliers. For small samples, try a log transformation, or use the Mann–Whitney U test (independent groups) or the Wilcoxon signed-rank test (paired). Both answer a slightly different question than a comparison of means.
How many groups can a t-test compare?
A t-test compares two groups at most, or one group with a fixed value. For three or more groups, use ANOVA. Running several t-tests instead raises the chance of a false positive with every extra comparison, because each test carries its own Type I error risk.
Key Takeaways
- Design picks the test. Count the groups and ask whether subjects repeat.
- Default to Welch's for two groups.
- The core is one ratio. t is the difference over its standard error; p comes from the t-distribution at the right df.
- Say "fail to reject," never "accept."
- Report more than p. That is how to do a t-test properly, by hand, in a spreadsheet, in code or in a calculator: difference, interval and effect size.
Next, see how a t-test fits into wider statistical analysis.
References
- Microsoft. T.TEST function. support.microsoft.com. Syntax, tails and type arguments.
- Google. T.TEST. Google Docs Editors Help. Arguments and the equal-size range note.
- R Core Team. Student's t-Test (
t.test), stats package 4.6.0. Welch default,paired,mu. - SciPy. scipy.stats.ttest_ind. docs.scipy.org. See also
ttest_relandttest_1samp. - Delacre, M., Lakens, D., and Leys, C. (2017). Why psychologists should by default use Welch's t-test instead of Student's t-test. International Review of Social Psychology, 30(1), 92 to 101.