Skip to content
Statculator

Statistical TestsStatistical Tables & Critical Values

One-Sample t-Test: Formula, Assumptions and Worked Example

Learn the one-sample t-test: what it is used for, the t statistic formula, how to calculate t step by step, a worked example by hand and how to report it.

By Hira Noor, BS Mathematics · Updated · 10 min read

Summary

The one-sample t-test checks whether the mean of a single sample differs from a claimed or target value μ₀ when the population standard deviation is unknown. It computes t = (x̄ − μ₀) / (s / √n), the distance between the sample mean and μ₀ in standard errors, and compares it with a t distribution with n − 1 degrees of freedom. A small p-value means the data are inconsistent with μ₀.

Key takeaways

  • H₀: μ = μ₀. The statistic is t = (x̄ − μ₀) / (s / √n) with df = n − 1.
  • Use t when σ is estimated by the sample standard deviation s; use z only when σ is known.
  • A two-tailed test at level α rejects H₀ exactly when the (1 − α) confidence interval for μ excludes μ₀.
  • The data should be a random sample from a roughly normal population; normality matters less as n grows.
  • Report t, df and p with the sample mean, its confidence interval and Cohen’s d = (x̄ − μ₀) / s.
On this page
  1. What is a one-sample t-test used for?
  2. Assumptions
  3. One-sample t-test formula and degrees of freedom
  4. How to calculate the t statistic
  5. Worked example by hand
  6. One-tailed vs two-tailed tests
  7. t-test or z-test?
  8. One-sample vs two-sample t-test, paired t-test and ANOVA
  9. Confidence interval and effect size
  10. Running a one-sample t-test in R, Python, SPSS and Excel
  11. Reporting and common mistakes
  12. Frequently asked questions

What is a one-sample t-test used for?

The one-sample t-test compares one sample mean with a single fixed number, μ₀. That number comes from outside the data: a label claim (500 g per box), a specification, a historical average, a published norm or a theoretical value such as zero change. Typical uses:

  • Quality control. Does the mean fill weight, length or strength of a production run match its target?
  • Checking a claim. Do batteries last the 20 hours printed on the pack, or does a diet really average a 2 kg loss?
  • Comparing with a known benchmark. Is the mean test score at one school different from the national mean of 500?
  • Testing for any change at all. Is the mean of a set of change scores or measurement errors different from zero?
Try it: One-Sample t-Test CalculatorAlready have your data? Paste the values or enter the mean, SD and n to get t, df, the p-value and the confidence interval with every step shown.
Hypotheses
H₀: μ = μ₀ H₁: μ ≠ μ₀ (one-sided: μ < μ₀ or μ > μ₀)

The sample mean x̄ will almost never equal μ₀ exactly, so the real question is whether the gap is larger than sampling variation would explain. The test measures that gap in standard errors. If you are comparing two sets of measurements instead of one sample and one fixed value, you need the independent samples t-test or the paired t-test.

Assumptions

  • Random, independent observations. The values are a random sample from the population of interest, and one value does not influence another.
  • Numeric outcome. The variable is measured on an interval or ratio scale, so that a mean is meaningful.
  • Approximately normal population. With small samples, check a histogram or box plot for strong skew and outliers, or run the Shapiro–Wilk test. With roughly 30 or more observations, the test is reliable for most moderately non-normal populations because the sample mean is close to normally distributed.
  • σ is unknown. The population standard deviation is estimated by s. This is what makes it a t-test and not a z-test.

One-sample t-test formula and degrees of freedom

One-sample t statistic (the t-test equation)
t = (x̄ − μ₀) / (s / √n) df = n − 1

This is the equation for the t-test on one mean, and it is the same thing as the t value formula or test statistic formula you will see in textbooks. Here x̄ is the sample mean, s is the sample standard deviation (the n − 1 version), n is the sample size and s / √n is the standard error of the mean. The numerator is how far the sample mean sits from the hypothesized value; the denominator is how much sample means typically vary. Their ratio follows a t distribution with n − 1 degrees of freedom when H₀ is true.

The degrees of freedom are n − 1 because s is computed from deviations around x̄, and those n deviations must sum to zero: once n − 1 of them are known, the last is fixed. See Sample vs Population Standard Deviation: Which Should You Use? for the reasoning behind n − 1.

How to calculate the t statistic

To calculate the t value for a one-sample test by hand, work through six steps:

  1. Fix μ₀ and the alternative (≠, < or >) before looking at the data.
  2. Find the sample mean x̄ = Σx / n.
  3. Find the sample standard deviation s = √[Σ(x − x̄)² / (n − 1)].
  4. Find the standard error SE = s / √n.
  5. Divide the gap by the standard error: t = (x̄ − μ₀) / SE, and set df = n − 1.
  6. Convert t to a p-value with the t distribution, or compare |t| with the critical value from a t-table.

If you only have summary statistics, you can skip steps 2 and 3: a mean of 52, an SD of 6 and n = 16 against μ₀ = 50 give SE = 6 / 4 = 1.5 and t = 2 / 1.5 = 1.333 with 15 df. The P-Value from t Calculator turns any t and df into a p-value.

Worked example by hand

A machine is set to fill cereal boxes with 500 g. A quality inspector weighs a random sample of nine boxes from one shift. Test at α = 0.05 whether the mean fill weight differs from 500 g.

Fill weights and deviations from the sample mean (x̄ = 497 g)
BoxWeight x (g)x − x̄(x − x̄)²
149811
2503636
3495−24
449924
5492−525
6501416
7496−11
8494−39
9495−24
Total44730100

Step 1: Hypotheses

H₀: μ = 500 and H₁: μ ≠ 500. The test is two-tailed because both overfilling and underfilling are problems.

Step 2: Sample mean and standard deviation

x̄ = 4473 / 9 = 497 g. The squared deviations total 100, so s² = 100 / (9 − 1) = 12.5 and s = √12.5 = 3.5355 g.

Step 3: Standard error

SE = s / √n = 3.5355 / √9 = 3.5355 / 3 = 1.1785 g.

Step 4: t statistic

t = (497 − 500) / 1.1785 = −2.5456, with df = 9 − 1 = 8. The sample mean is about 2.5 standard errors below the target.

Step 5: p-value and decision

The two-tailed p-value is 2 · P(T₈ ≤ −2.5456) = 0.0344. The t-table critical value for α = 0.05 with 8 df is 2.306. Because |t| = 2.546 > 2.306, or equivalently p = 0.0344 < 0.05, reject H₀: the mean fill weight differs from 500 g, and the sample points to underfilling.

t distribution with 8 degrees of freedom. The two rejection regions lie beyond −2.306 and 2.306, and the observed t of −2.55 falls in the left rejection region.
The t distribution with 8 df. Each shaded tail holds 2.5% of the area, and the observed t = −2.55 lies beyond the critical value −2.306, so H₀ is rejected.
Try it: One-Sample t-Test CalculatorPaste the nine weights and set μ₀ = 500 to reproduce t, the p-value and the confidence interval, or enter a mean, SD and n.

One-tailed vs two-tailed tests

The alternative hypothesis decides which tail of the t distribution counts as evidence against H₀. The t statistic is the same in all three cases; only the p-value and the critical region change.

Three alternatives for the cereal example (t = −2.5456, df = 8)
AlternativeQuestion askedp-valueReject H₀ at α = 0.05 when
H₁: μ ≠ 500Is the mean fill off target in either direction?0.0344|t| ≥ 2.306
H₁: μ < 500Is the machine underfilling?0.0172t ≤ −1.860
H₁: μ > 500Is the machine overfilling?0.9828t ≥ 1.860

A one-tailed test has more power in the stated direction, but it cannot detect an effect in the other direction at all: the right-tailed p-value of 0.98 shows what happens when the data go the opposite way.

How to know if a test is one-tailed or two-tailed

Read the research question, not the data. If it asks whether the mean is different from, changed from or not equal to μ₀, the test is two-tailed. If it asks whether the mean is less than, below, at most, greater than or exceeds μ₀, and a result in the other direction would lead to the same decision as no effect, it is one-tailed. Fix the direction before collecting the data. If you would act on a difference in either direction, use two tails.

t-test or z-test?

The choice depends on one thing: whether the population standard deviation σ is known. If it is, the standard error σ / √n is a fixed number and the statistic z = (x̄ − μ₀) / (σ / √n) follows the standard normal distribution. If σ is estimated by s, the estimate adds uncertainty of its own, and the t distribution’s heavier tails account for it.

Two-tailed critical values at 95% confidence: t approaches z as n grows
Sample size ndft critical valuez critical value
542.7761.960
1092.2621.960
20192.0931.960
30292.0451.960
100991.9841.960

Suppose long-run records showed that this filling machine has σ = 3.5 g. Then z = (497 − 500) / (3.5 / √9) = −3 / 1.1667 = −2.571 and the two-tailed p = 0.0101 from the One-Sample Z-Test Calculator. Without that knowledge, reading the t statistic of −2.5456 against the normal curve would give p = 0.0109 where the correct value is 0.0344. With only nine observations, that shortcut makes the p-value about three times too small.

In practice σ is almost never known, so the t-test is the default at every sample size. The old rule “use z when n ≥ 30” only reflects that the two give nearly the same answer for large n.

One-sample vs two-sample t-test, paired t-test and ANOVA

The difference between a one-sample and a two-sample t-test is what the mean is compared with. A one-sample test compares one group with a fixed number; a two-sample test compares two groups with each other, so both means carry sampling error. Choose by the number of groups and how they are related:

Which test compares means in your design
DesignTestHypothesisdf
One group vs a fixed value μ₀One-sample t-testμ = μ₀n − 1
Two related measurements per subjectPaired t-testμ_d = 0pairs − 1
Two independent groupsTwo-sample (independent) t-testμ₁ = μ₂n₁ + n₂ − 2 (pooled)
Three or more independent groupsOne-way ANOVAμ₁ = μ₂ = … = μₖk − 1 and N − k

Use a one-way ANOVA instead of t-tests when there are three or more groups. Running every pairwise t-test inflates the chance of at least one false positive: with three groups and three tests at α = 0.05 it rises to as much as 14% (1 − 0.95³). With exactly two groups, ANOVA and the pooled t-test are equivalent (F = t²). For any other design, the test chooser walks through the options.

Confidence interval and effect size

Confidence interval for μ
x̄ ± t* · s / √n

With 8 df and 95% confidence the critical value is 2.306, so the interval is 497 ± 2.306 × 1.1785 = 497 ± 2.72, or 494.28 g to 499.72 g. The target of 500 lies just outside it. That is no coincidence: a two-tailed test at α = 0.05 rejects H₀ exactly when the 95% confidence interval excludes μ₀. The interval is the more informative of the two, because it shows every value of μ the data are compatible with. The Mean Confidence Interval Calculator computes it directly.

Cohen’s d for one sample
d = (x̄ − μ₀) / s t = d · √n

Here d = (497 − 500) / 3.5355 = −0.85: the mean fill is 0.85 standard deviations below target, a large standardized effect by Cohen’s benchmarks of 0.2, 0.5 and 0.8. In raw units the shortfall is 3 g, or 0.6% of the label weight. Whether that matters is a question for the quality standard, not for the p-value. The Effect Size Calculator reports d from either raw data or t and n.

Running a one-sample t-test in R, Python, SPSS and Excel

Every major package runs the test from the raw values and the test value μ₀. With the nine cereal weights, each one below returns t = −2.546, df = 8 and p = 0.034.

One-sample t-test commands for the cereal example (μ₀ = 500)
SoftwareCommand or menu
Rt.test(x, mu = 500); add alternative = "less" for a left-tailed test
Python (SciPy)scipy.stats.ttest_1samp(x, 500); add alternative="less" for a left-tailed test
SPSSAnalyze → Compare Means → One-Sample T Test, then enter 500 as the Test Value
ExcelNo one-sample option in T.TEST. Compute t with the formula above, then =T.DIST.2T(ABS(t), n-1) for the two-tailed p-value

Reporting and common mistakes

An APA-style sentence gives the sample mean and standard deviation, the test value, then t with its degrees of freedom, p, the effect size and the confidence interval: “The mean fill weight (M = 497.00 g, SD = 3.54) was below the 500 g target, t(8) = −2.55, p = .034, d = −0.85, 95% CI [494.28, 499.72].”

  • Taking μ₀ from the data. The test value must be fixed before you look at the sample. Testing against a number suggested by the same data makes the p-value meaningless.
  • Using another sample’s mean as μ₀. A mean estimated from a second sample has its own sampling error. Compare the two samples with an independent samples t-test.
  • Using z with a small sample and unknown σ. This understates the p-value, as the comparison above shows.
  • Ignoring an outlier in a small sample. Plot the data first. One extreme value can either create or hide a significant result.
  • Sampling for convenience. Nine consecutive boxes from one minute of production are not a random sample of the shift.
  • Stopping at the p-value. Report the confidence interval and effect size too; see What Is a P-Value? Meaning, Calculation and Common Mistakes.

Frequently asked questions

When should I use a one-sample t-test?

Use a one-sample t-test when you have one sample of numeric measurements and want to know whether its population mean differs from a specific value fixed in advance, and the population standard deviation is unknown. Typical test values are a label claim, a specification, a historical average or zero.

What is the difference between a one-sample t-test and a z-test?

The z-test requires the population standard deviation σ to be known; the t-test estimates it with the sample standard deviation s. Because s is itself uncertain, the t-test uses a t distribution with n − 1 degrees of freedom, which has heavier tails and gives larger p-values in small samples. For large samples the two tests give almost identical results.

What are the degrees of freedom in a one-sample t-test?

The degrees of freedom are n − 1, one less than the sample size. One degree of freedom is used up by estimating the mean before the standard deviation can be computed. A sample of 9 values gives df = 8.

How do you calculate the t statistic for a one-sample t-test?

Subtract the test value μ₀ from the sample mean, then divide by the standard error s / √n: t = (x̄ − μ₀) / (s / √n). For a sample of 9 with mean 497, s = 3.54 and μ₀ = 500, the standard error is 3.54 / 3 = 1.18 and t = −3 / 1.18 = −2.55 with 8 degrees of freedom.

What is the difference between a one-sample and a two-sample t-test?

A one-sample t-test compares the mean of one group with a fixed number chosen in advance, such as a target or a published norm. A two-sample t-test compares the means of two independent groups with each other, so it has to allow for sampling error in both means. If each subject is measured twice, use a paired t-test instead.

Can I run a one-sample t-test with a small sample?

Yes. The t distribution was designed for small samples, and the test is exact when the population is normal. The catch is that normality is hard to verify with few values, so inspect the data for skew and outliers, and consider the Wilcoxon signed-rank test if they are present.

How is the one-sample t-test related to a confidence interval?

They use the same standard error and the same t critical value. A two-tailed one-sample t-test at significance level α rejects H₀: μ = μ₀ exactly when the (1 − α) confidence interval for the mean does not contain μ₀. For α = 0.05, that is the 95% confidence interval.

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

Mathematically, yes. A paired t-test first reduces each pair to a single difference and then runs a one-sample t-test on those differences against μ₀ = 0. The formula, the degrees of freedom (number of pairs minus 1) and the p-value are identical.

Further reading

Cite this page

Statculator. (2026, November 14). One-Sample t-Test: Formula, Assumptions and Worked Example. Retrieved November 14, 2026, from https://statculator.com/learn/one-sample-t-test/