Foundations · Inference
Degrees of Freedom Calculator
Every t, χ² and F test reports a number in parentheses — its degrees of freedom — and almost no one can say what it is. Here it is for each test, with the formula worked out and a plain explanation: degrees of freedom count the independent pieces of information left once you have spent some estimating the mean (or other parameters), and they fix the exact shape of the curve your result is judged against.
For the pooled (equal-variance) two-sample t-test. If the variances look unequal, use Welch's t instead.
The Welch–Satterthwaite approximation; the df it returns is usually not a whole number.
Subtract one df for every parameter you estimate from the same data — e.g. fitting a Poisson rate costs 1, a normal mean and SD cost 2. For testing fixed, fully-specified proportions, leave this at 0.
For a contingency table cross-tabulating two categorical variables.
N is everyone, pooled across all groups.
Simple regression has p = 1, which gives the residual df of n − 2 that the correlation test also uses.
Result
In plain English
Imagine you are told four numbers must average to 10. You can pick the first three freely — anything you like — but the fourth is then forced: it has to be whatever makes the total come to 40. Three of the four values were free to vary; one was spoken for. That is the whole idea. Degrees of freedom are the number of values in a calculation that are genuinely free to move once you have imposed the constraints — and each quantity you estimate from the data (a mean, a slope, an expected count) imposes one constraint and costs you one degree of freedom.
- degrees of freedom (df)
- The number of independent pieces of information available for estimating variability, after subtracting one for each parameter already estimated from the same data. It is the number reported in parentheses, e.g. t(19) or F(3, 36).
- why n − 1 for a sample
- To measure spread you need the mean, but the mean is itself estimated from the data. Once it is fixed, the deviations from it must sum to zero, so only n − 1 of them are free — the last is determined. Dividing the sum of squares by n − 1 (Bessel's correction) corrects the resulting under-estimate of the variance.
- why it sets the curve's shape
- A test statistic is judged against a reference distribution whose shape depends only on the df. Low df means more uncertainty about the spread, so the t-distribution has fatter tails and a larger critical value; as df grows it tightens toward the normal curve.
- between vs within (ANOVA)
- Comparing k groups splits the total n − 1 df into k − 1 between groups (the signal) and N − k within groups (the noise). The F-ratio weighs one against the other, which is why F carries two df.
- not the same as sample size
- df is the sample size minus the parameters you spent estimating. More observations buy more df, but two designs with the same n can have different df, and a large df is not automatically a "better" test — it just means a reference curve closer to the normal.
Frequently asked
What are degrees of freedom, in plain terms?
They are the number of values in a calculation that are free to vary once the constraints are in place. If five numbers must average to a known value, four can be anything but the fifth is then fixed — so there are four degrees of freedom. In statistics the binding constraints are the parameters you estimate from the data: each estimated mean, slope or expected count uses up one degree of freedom, leaving fewer independent pieces of information for measuring the leftover variability.
Why is it n − 1 and not n for the sample standard deviation?
Because the deviations are taken from the sample mean, not the true mean, and the sample mean is fitted to those very numbers. That forces the deviations to sum to zero, so the last one carries no new information — only n − 1 are free. Dividing by n would systematically under-estimate the variance (the data hug their own mean too closely); dividing by n − 1, called Bessel's correction, fixes the bias. With the population mean known in advance you would divide by n and keep all n degrees of freedom.
How do I find the degrees of freedom for a t-test, chi-square or ANOVA?
It depends on the test. A one-sample or paired t-test has n − 1; a pooled two-sample t-test has n₁ + n₂ − 2; Welch's t uses the Satterthwaite approximation and is usually fractional. A chi-square goodness-of-fit test has k − 1 (minus one more for every parameter estimated), and a test of independence has (rows − 1)(columns − 1). One-way ANOVA has k − 1 between groups and N − k within. Linear regression with p predictors has n − p − 1 residual degrees of freedom. Pick the test above and the calculator shows the formula with your numbers plugged in.
Does a higher degrees of freedom make a test better or more reliable?
More df generally means more power and a reference distribution closer to the normal — so a smaller critical value and a tighter interval. But df is not a dial you can turn on its own: it rises only with more data or a simpler model, and a test with df = 200 is not "better" than one with df = 20 if the extra observations came from a biased sample. Above roughly 30 df the t-distribution is almost indistinguishable from the normal, so further df buys very little; below about 10 it matters a great deal, and small-sample assumptions (normality especially) deserve real scrutiny.