Written and maintained by CASRAI Editorial Board
Last updated
A test statistic is a single number computed from your sample data that measures how far the data sit from what the null hypothesis predicts. You compare it with a critical value, or convert it to a p-value, to decide whether the data are surprising enough to reject the null hypothesis. This guide gives the formula for the most common case (the t statistic), a worked example with every step of the arithmetic, how to read the result, common mistakes, and how to calculate it in Excel, R and Python. Formulas and the worked example follow the NIST/SEMATECH e-Handbook of Statistical Methods, checked on 2026-10-28.
What is a test statistic?
NIST puts it this way: critical values for a test of hypothesis “depend upon a test statistic, which is specific to the type of test.” The null hypothesis is rejected if the test statistic lies in the rejection region, the range of values the statistic is unlikely to take when the null hypothesis is true. Different tests use different statistics, so “the test statistic formula” depends on which test you are running. The statistic compresses the whole sample into one number, which makes a decision rule possible. For the wider idea of a test, see the CASRAI entry on statistical test, and for how the statistic maps to a probability, p-value.
Test statistic formula for the one-sample t-test
When you compare a sample mean with a hypothesised value and the population standard deviation must be estimated from the data (the more typical case), NIST gives:
t = (Ybar - mu0) / (s / sqrt(N))
- Ybar is the sample mean.
- mu0 is the value of the mean stated in the null hypothesis, H0: mu = mu0.
- s is the sample standard deviation, computed with N – 1 in the denominator.
- N is the sample size. The statistic has N – 1 degrees of freedom.
The numerator measures the distance between what you observed and what the null hypothesis says. The denominator, s divided by the square root of N, is the standard error of the mean, so the statistic is a distance measured in standard errors.
Test statistic formula for the two-sample t-test
For two independent samples with unequal variances, NIST gives:
T = (Y1bar - Y2bar) / sqrt(s1^2 / N1 + s2^2 / N2)
Here N1 and N2 are the sample sizes, Y1bar and Y2bar the sample means, and s1^2 and s2^2 the sample variances. The null hypothesis is that the two means are equal, and NIST rejects it if |T| exceeds the critical value t(1 – alpha/2, nu), where nu is the degrees of freedom.
Test statistic examples with the arithmetic shown
Example 1: one-sample t-test (NIST wafer example)
NIST tests whether the process average for wafer particle counts, historically 50 counts per wafer, still holds in a sample of 10 silicon wafers. The counts are 50, 48, 44, 56, 61, 52, 53, 55, 67 and 51. The test is two-sided at alpha = 0.05.
- Sample mean: the counts sum to 537, so Ybar = 537 / 10 = 53.7.
- Sample standard deviation: s = 6.567 (NIST reports 6.567 counts).
- Standard error: 6.567 / sqrt(10) = 6.567 / 3.1623 = 2.077.
- Test statistic: t = (53.7 – 50) / 2.077 = 3.7 / 2.077 = 1.782.
- Critical value with 9 degrees of freedom: t(0.975, 9) = 2.262.
- Decision: |1.782| is less than 2.262, so the test statistic is outside the rejection region and the null hypothesis is not rejected. NIST concludes that “we cannot reject the null hypothesis and, therefore, we may continue to assume the process mean is 50 counts.”
Example 2: two-sample t-test (small illustrative data)
These numbers are invented for illustration. Group A: 12, 15, 14, 10, 13, 16. Group B: 9, 11, 10, 8, 12, 10.
- Means: Y1bar = 80 / 6 = 13.333 and Y2bar = 60 / 6 = 10.
- Sample variances (N – 1 denominator): s1^2 = 4.667 and s2^2 = 2.
- Standard error: sqrt(4.667 / 6 + 2 / 6) = sqrt(0.7778 + 0.3333) = sqrt(1.1111) = 1.054.
- Test statistic: T = (13.333 – 10) / 1.054 = 3.162.
Run as a Welch test in software, this gives about 8.6 degrees of freedom and p of about 0.012.
How to interpret a test statistic
| What you see | What it means |
|---|---|
| Statistic near 0 | The sample is close to what the null hypothesis predicts. |
| Statistic far from 0 (large absolute value) | The sample is far from the null prediction, measured in standard errors. |
| Statistic beyond the critical value | It lies in the rejection region, so the null hypothesis is rejected at that alpha. |
| Statistic inside the critical values | The null hypothesis is not rejected. This is not proof that it is true. |
The p-value is the other route to the same decision. NIST defines it as the probability of the test statistic being at least as extreme as the one observed, given that the null hypothesis is true; the null hypothesis is rejected if the p-value is smaller than alpha. NIST also notes that alpha = 0.05 “implies that the null hypothesis is rejected 5 % of the time when it is in fact true.”
For a one-sided test, NIST rejects with Ha: mu > mu0 if T > t(1 – alpha, nu), and with Ha: mu < mu0 if T < t(alpha, nu). A two-sided test splits alpha between the two tails.
Assumptions and common mistakes
- Using the wrong statistic for the design. The one-sample, two-sample and other formulas answer different questions. Pick the test first, then the statistic.
- Confusing a sample standard deviation with a standard error. The denominator of the t statistic is s / sqrt(N), not s.
- Forgetting the degrees of freedom. The critical value depends on them (N – 1 in the one-sample case).
- Treating “not rejected” as “proved”. Failing to reject means the data are compatible with the null hypothesis, not that it is established.
- Ignoring the model assumptions. t-tests assume the data are suitably close to normally distributed or the sample is large enough; see the Shapiro-Wilk test in R for one normality check, and the Kruskal-Wallis test in R for a rank-based alternative when comparing groups.
- Mixing tails. Using a one-sided critical value for a two-sided hypothesis changes the error rate.
How to report a test statistic
Reporting conventions differ between style guides, so check the one your journal or institution requires. A typical pattern gives the statistic, its degrees of freedom, and the exact p-value, for example: t(9) = 1.78, p = .108 for Example 1 (the p-value is computed in the code below). Add the sample means and standard deviations, and an effect size or confidence interval if your style asks for them.
How to calculate a test statistic in Excel, R or Python
Excel
With the counts in cells A2:A11 and the hypothesised mean of 50:
=(AVERAGE(A2:A11)-50)/(STDEV.S(A2:A11)/SQRT(COUNT(A2:A11)))
=T.INV.2T(0.05, 9)
The first formula returns 1.782 and the second the two-sided critical value, 2.262.
R
x <- c(50, 48, 44, 56, 61, 52, 53, 55, 67, 51)
t.test(x, mu = 50)
Python
from scipy import stats
x = [50, 48, 44, 56, 61, 52, 53, 55, 67, 51]
result = stats.ttest_1samp(x, popmean=50)
print(result.statistic, result.pvalue) # about 1.7818 and 0.1085
a = [12, 15, 14, 10, 13, 16]
b = [9, 11, 10, 8, 12, 10]
print(stats.ttest_ind(a, b, equal_var=False)) # statistic about 3.162
Frequently asked questions
What is a test statistic?
A number calculated from sample data that summarises how far the sample is from the null hypothesis. It is compared with critical values, or turned into a p-value, to decide whether to reject the null hypothesis.
What is the test statistic formula?
It depends on the test. For a one-sample t-test it is t = (Ybar – mu0) / (s / sqrt(N)); for a two-sample t-test with unequal variances it is T = (Y1bar – Y2bar) / sqrt(s1^2/N1 + s2^2/N2).
How do I know whether to reject the null hypothesis?
Reject it if the test statistic falls in the rejection region, meaning it is beyond the critical value, or equivalently if the p-value is smaller than alpha.
What is the difference between a test statistic and a p-value?
The test statistic is the distance measure computed from the data. The p-value is the probability of a statistic at least as extreme as the one observed if the null hypothesis is true.
Can a test statistic be negative?
Yes. For the t statistics above the sign shows which mean is larger. NIST’s two-sample example reports T = -12.62059. For a two-sided test, the absolute value is compared with the critical value.
Where can I read the basics of statistics first?
See what is statistics for an overview, and z-scores in SPSS for a related standardised score.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, 1-sample t-test: https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm (checked 2026-10-28)
- NIST/SEMATECH e-Handbook, 2-sample t-test: https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (checked 2026-10-28)
- NIST/SEMATECH e-Handbook, worked example, section 7.2.2: https://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm (checked 2026-10-28)
- NIST/SEMATECH e-Handbook, section 7.1.3.1, critical values and p-values: https://www.itl.nist.gov/div898/handbook/prc/section1/prc131.htm (checked 2026-10-28)








