Degrees of Freedom Calculator

Find the degrees of freedom for a t-test, chi-square test, or ANOVA. Pick your test, enter the sample sizes or table dimensions, and get df instantly with the exact formula shown.

Quick Facts

Method
Standard df formulas: n−1, n₁+n₂−2, k−1, (r−1)(c−1)
Degrees of freedom = independent values free to vary after constraints.

Your Results

Calculated
Degrees of freedom
-
df for your test
Formula used
-
How df is defined here

Ready

Choose a test, enter your values, and calculate.

What degrees of freedom means

Degrees of freedom (df) is the number of values in a statistical calculation that are free to vary once you impose the constraints the method requires. If you have a sample of n numbers and you fix their mean, only n − 1 of them can take any value you like — the last one is forced, because the deviations from the mean must add up to zero. That single lost degree of freedom is why the sample variance divides by n − 1 rather than n (Bessel's correction), and it is why almost every basic test loses one degree of freedom for each parameter it estimates from the data.

Degrees of freedom matter because they select the exact shape of the reference distribution you use to turn a test statistic into a p-value or a critical value. A t-distribution with 5 df has much heavier tails than one with 50 df; a chi-square distribution with 1 df looks nothing like one with 10 df. Get df wrong and you read the wrong row of the table, which can flip a result from "significant" to "not."

The formulas this calculator uses

  • One-sample or paired t-test: df = n − 1, where n is the number of observations (or the number of paired differences). A paired test treats each pair's difference as a single value, so 20 pairs give df = 19.
  • Two-sample t-test (pooled, equal variances): df = n₁ + n₂ − 2, because two group means are estimated. For Welch's unequal-variance t-test the df is smaller and non-integer (the Welch–Satterthwaite approximation, which needs the two sample variances); this tool covers the standard pooled case.
  • Chi-square goodness-of-fit: df = k − 1, where k is the number of categories. Subtract one more df for each additional parameter you estimate from the data (for example, df = k − 2 if you fit a Poisson mean before testing).
  • Chi-square test of independence: df = (r − 1)(c − 1) for an r × c contingency table.
  • One-way ANOVA: between-groups df = k − 1, within-groups (error) df = N − k, and total df = N − 1, where k is the number of groups and N is the total number of observations. Note that (k − 1) + (N − k) = N − 1, so the two component df always add to the total.

Worked examples

  • A one-sample t-test on 25 measurements: df = 25 − 1 = 24.
  • A two-sample t-test comparing groups of 15 and 12: df = 15 + 12 − 2 = 25.
  • A goodness-of-fit test across 6 categories: df = 6 − 1 = 5.
  • A 3 × 4 contingency table: df = (3 − 1)(4 − 1) = 2 × 3 = 6.
  • One-way ANOVA with 4 groups and 40 total observations: between df = 3, within df = 36, total df = 39.

Frequently Asked Questions

Why is degrees of freedom n − 1 and not n?
When you estimate the sample mean from the data, you use up one piece of information. Once the mean is fixed, the deviations from it must sum to zero, so only n − 1 of them are free to vary. Dividing the sum of squared deviations by n − 1 (instead of n) gives an unbiased estimate of the population variance.
Can degrees of freedom be a fraction?
Yes. Welch's t-test for two groups with unequal variances produces a non-integer df from the Welch–Satterthwaite formula — a value like 23.7 is normal and you interpolate between table rows or let software compute the exact p-value. The classic textbook formulas here (n − 1, n₁ + n₂ − 2, k − 1, (r − 1)(c − 1)) always give whole numbers.
Does a paired t-test use n or n − 1?
A paired t-test reduces each matched pair to a single difference, then runs a one-sample t-test on those differences. So df = n − 1, where n is the number of pairs — not the total count of individual measurements.
How does df relate to sample size and power?
More data means more degrees of freedom, which makes the t and F distributions tighter and the critical values smaller — so a given effect is easier to detect. As df grows large (roughly 30+), the t-distribution converges to the standard normal (z) distribution, which is why large-sample tests often just use z.