What Are Degrees of Freedom?
Degrees of freedom (df) are the number of values in a calculation that are free to vary once the constraints on them are fixed. Every parameter you estimate from the sample, such as a mean, removes one degree of freedom, so df is usually the number of independent observations minus the number of estimated parameters.
Take five numbers that must average 10. You can pick four of them freely, say 8, 12, 9 and 11, but the fifth has to be 10 for the total to reach 50. Five values, one constraint, four degrees of freedom.
The count matters because it selects the exact distribution behind your p-value or confidence interval. A t distribution with 4 df has much heavier tails than one with 40, so the same test statistic can be significant in a large sample and not in a small one. The F distribution and the chi-square distribution also change shape with df. The sections below give the formula for each test, the reasoning behind it, and worked numbers you can check against the calculator. For the wider theory, the degrees of freedom guide goes further.
Degrees of Freedom Formulas by Test
Every df formula follows the same rule: independent observations minus estimated parameters. The four cards cover every test in the calculator.
t-Tests
One-sample or paired: df = n − 1
Two-sample, pooled: df = n₁ + n₂ − 2
Two-sample, Welch: Welch–Satterthwaite
(usually not a whole number)
n = observations (or pairs)
n₁, n₂ = the two group sizes
Chi-Square Tests
Independence: df = (r − 1)(c − 1)
Goodness of fit: df = k − 1 − m
r = rows, c = columns
k = categories
m = parameters estimated from the data
ANOVA and F-Test
One-way: between = k − 1
within = N − k
total = N − 1
F-test: df₁ = n₁ − 1, df₂ = n₂ − 1
k = groups, N = all observations
Regression
Model df = p
Residual df = n − p − 1
Total df = n − 1
p = predictors (not counting the intercept)
Simple regression and Pearson r: n − 2
Same df, different notation
Textbooks and software write the same quantity in different ways, which is the main reason people think two sources disagree. This table maps the common variants.
| You may see | Also written | What it means |
|---|---|---|
| N − 2 (two-sample t) | n₁ + n₂ − 2 | N is the total across both groups, so N = n₁ + n₂. Identical value. |
| n − 2 (regression) | n − p − 1 with p = 1 | Simple regression is the one-predictor case of the general formula. |
| Model / error / total | Regression / residual / total, or between / within / total | Different names for the same three-part split of df. |
| k − 1 (one-way ANOVA) | a − 1 (two-way, factor A) | k counts groups in a one-way design; a and b count levels of each factor. |
| df | d.f., dof, ν (nu) | Same quantity, different symbol. |
How to Calculate Degrees of Freedom: Count the Constraints
To calculate degrees of freedom, count the independent observations in your data and subtract one for every parameter you estimate from that same data. What remains is df. Here is the method with one running example: a café times 25 espresso shots and compares the mean with a target.
A one-sample t-test estimates one mean. A pooled two-sample t-test estimates two. A regression with p predictors estimates p + 1 coefficients, because the intercept counts.
Use n for one sample, the group sizes for two samples, and the number of pairs for a paired design. Pairs count once because the test works on their differences. For chi-square, count rows and columns, not people. The café has n = 25.
25 shots minus 1 estimated mean gives df = 24. For two groups of 12 and 15 with pooled variance, 27 observations minus 2 means gives df = 25.
With df = 24 and α = 0.05 (two-tailed), the t critical value is 2.064. A test statistic beyond ±2.064 is significant at the 5% level. Read it from a t table or from the calculator above.
Result: n = 25, df = 24, t* = ±2.064. Enter n = 25 in the One-Sample tab to confirm.
Why Does Sample Variance Use n − 1?
Sample variance divides by n − 1 because the sample mean comes from the same data, which forces the deviations to sum to zero and leaves only n − 1 of them free. Dividing by n would underestimate the population variance on average.
Try the values 4, 7 and 9. The mean is 6.67 and the deviations are −2.67, 0.33 and 2.33. They add up to zero, so once you know any two, the third is fixed. Three data points, two free deviations.
There is a second way to see it. The data sit closer to their own mean than to the unknown population mean, so squared deviations around the sample mean come out too small. Dividing by n − 1 scales the total back up and makes the variance estimate unbiased on average. The adjustment is known as Bessel's correction. The standard deviation stays very slightly low even after the correction, because a square root is not a linear operation. GraphPad's FAQ on n − 1 gives a short non-mathematical version of the argument.
For the formulas themselves, see variance, standard deviation and population vs sample, or check your own numbers with the variance calculator.
Degrees of Freedom for a Two-Sample t-Test: Pooled vs Welch
Use pooled df (n₁ + n₂ − 2) only when you can defend equal population variances. Otherwise use Welch's df, which adjusts for unequal variances and unequal group sizes. Welch's value always falls between the smaller group's n − 1 and n₁ + n₂ − 2, and it is usually not a whole number.
The pooled test assumes one shared variance, so it spends two df on the two means and nothing else. Welch's test keeps the variances separate and approximates the df of the resulting standard error with the Welch–Satterthwaite equation. Wikipedia's entry on Welch's t-test shows the derivation.
df = (s₁²/n₁ + s₂²/n₂)² / [ (s₁²/n₁)²/(n₁ − 1) + (s₂²/n₂)²/(n₂ − 1) ]Table: Pooled df vs Welch df as the standard deviations and group sizes change
| Scenario | n₁ / s₁ | n₂ / s₂ | Pooled df | Welch df |
|---|---|---|---|---|
| Equal SDs, equal n | 20 / 5 | 20 / 5 | 38 | 38.00 |
| Second SD twice as large | 20 / 5 | 20 / 10 | 38 | 27.94 |
| Second SD four times as large | 20 / 5 | 20 / 20 | 38 | 21.37 |
| Noisier group is the small one | 10 / 8 | 40 / 4 | 48 | 10.15 |
| Noisier group is the large one | 10 / 4 | 40 / 8 | 48 | 29.25 |
| Worked example below | 12 / 4.2 | 15 / 9.8 | 25 | 19.84 |
With equal SDs and equal group sizes, Welch returns exactly the pooled value of 38. When the second SD is four times the first, Welch df drops to about 21, roughly half. Unequal group sizes make the gap bigger. When the noisier group is also the small one (n = 10, s = 8 against n = 40, s = 4), Welch df collapses to 10.15, barely above that group's own n − 1 of 9, while the pooled formula still claims 48. That pairing is where the pooled test most often reports p-values that are too small.
Worked Welch example
s₁²/n₁ = 4.2² / 12 = 1.4700 | s₂²/n₂ = 9.8² / 15 = 6.4027 | sum = 7.8727
(sum)² = 7.8727² = 61.979
1.4700²/11 = 0.1964 | 6.4027²/14 = 2.9282 | sum = 3.1246
61.979 / 3.1246 = 19.84
Result: df = 19.84, so t* = ±2.087 at α = 0.05 (two-tailed). A printed table needs a whole-number row, so round down to 19 and use 2.093. The pooled df of 25 would give 2.060, a cutoff that is too lenient for these data.
Software uses the unrounded df for the p-value. Rounding down for a table lookup gives a slightly larger critical value, which errs on the cautious side. For the decision between the two tests, see equal vs unequal variance, the Welch's t-test guide and the two-sample t-test page.
Degrees of Freedom for Chi-Square Tests
For a chi-square test of independence, df = (rows − 1)(columns − 1). For a goodness-of-fit test, df = categories − 1 − the number of parameters estimated from the data.
In a contingency table the row and column totals are fixed by the data. In a 3 × 4 table you can fill 2 × 3 = 6 cells freely and the remaining six are forced by the totals, so df = 6. A 2 × 2 table has just 1 df. Sample size does not appear in the formula: a 3 × 4 table has 6 df whether it holds 60 observations or 6,000. Penn State's STAT 504 notes walk through the same logic.
A goodness-of-fit test starts at k − 1 because the expected counts must add up to the observed total. Every parameter fitted from the same data costs one more. Testing 6 count categories against a Poisson model whose mean was estimated from the data gives df = 6 − 1 − 1 = 4. Skipping that last subtraction is the most common slip with this test.
The shape of the distribution follows df. With 1 or 2 df the curve starts high and falls away. From 3 df the peak moves right (the mode sits at df − 2) and the skew softens as df grows. That is why the 5% critical value climbs from 3.841 at df = 1 to 12.592 at df = 6. Related pages: chi-square test, goodness-of-fit test, how to read a chi-square table and the chi-square calculator.
Degrees of Freedom for ANOVA and the F-Test
ANOVA splits total df into a between-group part and a within-group part, and the F-test needs both: numerator df = k − 1 and denominator df = N − k in a one-way design. The parts always add up to N − 1.
Table: ANOVA degrees of freedom partition
| Source | Formula | One-way (k = 4, N = 28) | Two-way (3 × 4, r = 5) |
|---|---|---|---|
| Between groups / Factor A | k − 1 or a − 1 | 3 | 2 |
| Factor B | b − 1 | n/a | 3 |
| Interaction A × B | (a − 1)(b − 1) | n/a | 6 |
| Within groups / Error | N − k or ab(r − 1) | 24 | 48 |
| Total | N − 1 or abr − 1 | 27 | 59 |
Each df is also the divisor that turns a sum of squares into a mean square, so MS = SS / df and F = MSbetween / MSwithin. The F table is read with numerator df first and denominator df second, and swapping them changes the answer. At α = 0.05, F(3, 24) = 3.009 but F(24, 3) = 8.639.
The F-test for two variances uses df₁ = n₁ − 1 and df₂ = n₂ − 1, with the larger sample variance in the numerator. A two-tailed version puts α/2 in the upper tail and finds the lower cutoff as 1 / F(df₂, df₁). More detail: ANOVA, two-way ANOVA, F-test, the ANOVA calculator and the two-way ANOVA calculator.
Degrees of Freedom for Regression and Correlation
In a regression with p predictors and an intercept, residual df = n − p − 1, model df = p and total df = n − 1. Simple linear regression is the p = 1 case, so residual df = n − 2.
Each estimated coefficient, including the intercept, costs one df. With 50 observations and one predictor you estimate 2 coefficients and keep 48 residual df. That is the number R prints in the line "Residual standard error … on 48 degrees of freedom". The t-test and confidence interval for each coefficient use the residual df, and the overall F-test uses (p, n − p − 1). Yale's course notes show the same three-way split for simple regression.
Testing a Pearson correlation also uses n − 2, because it is equivalent to the slope test in simple regression. As p approaches n − 1, residual df approaches 0 and the model can fit almost any data, which is overfitting. At df = 0 the error variance cannot be estimated at all. See simple linear regression, multiple linear regression, Pearson correlation and residuals, or use the simple linear regression calculator and the correlation calculator.
Critical Values by Degrees of Freedom
As df grows, the t critical value shrinks toward the normal value of 1.960 (95%, two-tailed). The gap is large below 10 df and small above 30.
Table: t critical values by degrees of freedom (two-tailed)
| df | 95% (α = 0.05) | 99% (α = 0.01) | 95% cutoff vs z |
|---|---|---|---|
| 1 | 12.706 | 63.657 | +548.3% |
| 2 | 4.303 | 9.925 | +119.5% |
| 3 | 3.182 | 5.841 | +62.4% |
| 5 | 2.571 | 4.032 | +31.2% |
| 10 | 2.228 | 3.169 | +13.7% |
| 20 | 2.086 | 2.845 | +6.4% |
| 30 | 2.042 | 2.750 | +4.2% |
| 60 | 2.000 | 2.660 | +2.1% |
| 120 | 1.980 | 2.617 | +1.0% |
| ∞ (normal z) | 1.960 | 2.576 | 0% |
At 5 df the 95% cutoff is 2.571, about 31% wider than z. By 30 df it is 2.042, about 4% wider, and by 120 df the difference is about 1%. A small study therefore needs a larger test statistic to reach significance. For lookups see how to read a t table and the t-distribution table, plus the full set of statistical tables.
Table: χ² critical values (right tail)
| df | α = 0.05 | α = 0.01 |
|---|---|---|
| 1 | 3.841 | 6.635 |
| 2 | 5.991 | 9.210 |
| 3 | 7.815 | 11.345 |
| 4 | 9.488 | 13.277 |
| 5 | 11.070 | 15.086 |
| 6 | 12.592 | 16.812 |
| 8 | 15.507 | 20.090 |
| 10 | 18.307 | 23.209 |
| 15 | 24.996 | 30.578 |
| 20 | 31.410 | 37.566 |
Table: F critical values, α = 0.05 (right tail)
| Numerator df | Denominator df | F* |
|---|---|---|
| 1 | 10 | 4.965 |
| 2 | 20 | 3.493 |
| 3 | 24 | 3.009 |
| 4 | 30 | 2.690 |
| 5 | 40 | 2.449 |
| 3 | 10 | 3.708 |
Chi-square and F tests are right-tailed, so α sits entirely in the upper tail. For other df and α levels use the calculator above, the critical value calculator, the chi-square table and the F table. To turn a test statistic and df into a p-value, use the p-value calculator.
Worked Examples
Each row below can be reproduced in the calculator. Critical values are for α = 0.05, two-tailed for t.
Table: Degrees of freedom and critical values for eight common situations
| Scenario | Calculation | df | Critical value |
|---|---|---|---|
| Coffee shop times 25 espresso shots (one-sample t) | n − 1 = 25 − 1 | 24 | ±2.064 |
| 18 runners timed before and after training (paired t) | pairs − 1 = 18 − 1 | 17 | ±2.110 |
| Two classes, 12 and 15 students, equal variances (pooled t) | n₁ + n₂ − 2 = 12 + 15 − 2 | 25 | ±2.060 |
| Same classes, SDs of 4.2 and 9.8 (Welch t) | Welch–Satterthwaite | 19.84 | ±2.087 |
| Survey answers by 3 age bands and 4 regions (independence) | (3 − 1)(4 − 1) | 6 | 12.592 |
| Poisson fit to 6 count categories, λ estimated (goodness of fit) | 6 − 1 − 1 | 4 | 9.488 |
| 4 diets, 28 participants (one-way ANOVA) | k − 1 = 3, N − k = 24 | 3 and 24 | 3.009 |
| 50 homes, 3 predictors (regression) | n − p − 1 = 50 − 3 − 1 | 46 | ±2.013 (t), 2.807 (F) |
The Welch row is the only one where df is not a whole number. The regression row lists t* for a single coefficient and F* for the whole model, which share the residual df of 46.
Where to Find Degrees of Freedom in R, Python and Excel
Statistical software prints df alongside the test statistic, so you rarely compute it by hand. What matters is knowing where to find it and what it should equal.
R
t.test(x, y) # Welch by default: prints df = 19.84
t.test(x, y, var.equal = TRUE) # pooled: df = n1 + n2 - 2
fit <- lm(y ~ x)
summary(fit) # "Residual standard error ... on 48 degrees of freedom"
df.residual(fit) # 48
chisq.test(table(a, b)) # prints X-squared, df and p-value
summary(aov(y ~ group)) # Df column: between and withinPython
from scipy import stats
res = stats.ttest_ind(a, b, equal_var=False)
res.df # Welch df (SciPy 1.11 and later)
chi2, p, dof, expected = stats.chi2_contingency(table)
stats.t.ppf(0.975, df) # t critical value, two-tailed 5%
stats.chi2.ppf(0.95, df) # chi-square critical value
stats.f.ppf(0.95, df1, df2) # F critical value
import statsmodels.api as sm
model = sm.OLS(y, sm.add_constant(X)).fit()
model.df_model, model.df_resid # p and n - p - 1Excel
=T.INV.2T(0.05, 24) t critical value, two-tailed
=CHISQ.INV.RT(0.05, 6) chi-square critical value
=F.INV.RT(0.05, 3, 24) F critical value (numerator df first)The Data Analysis ToolPak t-test output also lists df. If the number in your software differs from this page, check which variance assumption it used, since many programs default to Welch. The statistics for Python guide covers more of the Python side.
How to Report Degrees of Freedom in APA Style
Put df in parentheses directly after the test symbol, then the test statistic and the exact p-value. Use two or fewer decimals for the statistic and three for p, without a leading zero. For Welch's test, report the fractional df.
Table: APA reporting formats (illustrative values; each p-value matches its statistic and df)
| Test | Format | Example |
|---|---|---|
| One-sample or paired t | t(df) = value, p = value | t(24) = 2.31, p = .030 |
| Welch t | t(df) = value, p = value | t(19.84) = 2.10, p = .049 |
| Pearson correlation | r(df) = value, p = value | r(48) = .35, p = .013 |
| Chi-square | χ²(df, N = total) = value, p = value | χ²(6, N = 200) = 14.20, p = .027 |
| ANOVA | F(df between, df within) = value, p = value | F(3, 24) = 4.12, p = .017 |
| Regression, overall | F(df model, df residual) = value, p = value | F(3, 46) = 5.62, p = .002 |
Reporting df lets a reader check your result and recover the sample size. See statistical interpretation for how to word results, and p-values for what the number means.
Common Degrees of Freedom Mistakes
Most df errors come from counting the wrong thing: observations instead of independent observations, or forgetting a parameter that was estimated. These are the eight that come up most.
| Mistake | Why it is wrong | Correct approach |
|---|---|---|
| Using n for a one-sample t-test | The mean is estimated from the same data, which costs one df. | df = n − 1 |
| Treating paired data as two samples | Each pair gives one difference. 18 pairs have 17 df, not 34. | df = pairs − 1 |
| Pooled df with unequal variances | It overstates the information when one group is much noisier. | Use Welch's df |
| Rounding Welch df up | A higher df gives a smaller critical value and makes the test too liberal. | Round down for tables, or use the exact value in software |
| Basing chi-square df on sample size | df depends on the table's dimensions, not on how many people are in it. | (r − 1)(c − 1) |
| Ignoring fitted parameters in goodness of fit | A Poisson mean or normal SD estimated from the data uses up df. | k − 1 − m |
| Swapping numerator and denominator df | The F distribution is not symmetric in its two df. | F(df between, df within) |
| Forgetting the intercept in regression | The intercept is an estimated coefficient. | n − p − 1, not n − p |
For other frequent errors in analysis and reporting, see common statistics mistakes.
Degrees of Freedom Glossary
Key terms used on this page, with the symbol or formula each one goes with. More definitions live in the statistics glossary.
| Term | Symbol / Formula | Plain-English Definition | Primary Use |
|---|---|---|---|
| Degrees of freedom | df = n − (estimated parameters) | Number of values free to vary after constraints are applied | Choosing the t, χ² or F distribution |
| Constraint | Σ(x − x̄) = 0 | A condition the data must satisfy, such as deviations summing to zero | Counting free values |
| Estimated parameter | x̄, b₀, b₁, λ | A quantity calculated from the sample and then reused in the test | Subtracted from n to get df |
| Bessel's correction | s² = Σ(x − x̄)² / (n − 1) | Dividing by n − 1 so the sample variance is unbiased | Sample variance and SD |
| Welch–Satterthwaite equation | df = (s₁²/n₁ + s₂²/n₂)² / … | Approximate df for a standard error built from two separate variances | Welch's t-test |
| Residual df | n − p − 1 | Observations left after estimating all regression coefficients | t-tests on coefficients |
| Numerator df | k − 1 or df₁ | df of the variance estimate on top of the F ratio | F table lookup |
| Denominator df | N − k or df₂ | df of the variance estimate on the bottom of the F ratio | F table lookup |
| Critical value | t*, χ²*, F* | The cutoff a test statistic must pass at a chosen α and df | Hypothesis test decisions |
| t distribution | t(df) | Bell-shaped, heavier tails than the normal when df is small | Means with unknown σ |
| Chi-square distribution | χ²(df) | Right-skewed distribution of a sum of squared standard normals | Counts and categorical data |
| F distribution | F(df₁, df₂) | Distribution of a ratio of two variance estimates | ANOVA and variance tests |
| Contingency table | r × c | Grid of counts cross-classified by two categorical variables | Chi-square independence test |
| Mean square | MS = SS / df | A sum of squares divided by its df, giving a variance estimate | ANOVA and regression tables |
Related Calculators, Guides and Tables on Statistics Fundamentals
Degrees of freedom feed into most of inferential statistics. These pages continue from here, and the calculators hub lists every tool.
Sources and Further Reading
References used on this page:
- Wikipedia. Welch's t-test. en.wikipedia.org
- Wikipedia. Welch–Satterthwaite equation. en.wikipedia.org
- Wikipedia. Bessel's correction. en.wikipedia.org
- GraphPad. Why does the SD formula use n − 1? (FAQ 1383). graphpad.com
- Penn State STAT 504. Chi-square tests of independence. online.stat.psu.edu
- Yale Statistics 101. ANOVA for regression. stat.yale.edu
Degrees of Freedom FAQ
Degrees of freedom (df) are the number of values in a calculation that can vary freely once the constraints are fixed. Every parameter you estimate from the sample, such as a mean, uses up one degree of freedom. In practice df is the number of independent observations minus the number of estimated parameters, and it decides which t, chi-square or F distribution is used for the p-value and critical value.
Count the independent observations, then subtract one for each parameter estimated from the same data. A one-sample t-test with 25 observations estimates one mean, so df = 25 − 1 = 24. A chi-square test of independence on a 3 × 4 table has df = (3 − 1)(4 − 1) = 6. The calculator above applies the right formula once you pick the test.
For a one-sample or paired t-test, df = n − 1, where n is the number of observations or pairs. For a two-sample t-test with pooled variance, df = n₁ + n₂ − 2. For Welch's t-test the Welch–Satterthwaite equation gives df, which is usually not a whole number and always lies between the smaller group's n − 1 and n₁ + n₂ − 2.
The sample mean is computed from the same data, so the deviations from it always sum to zero and only n − 1 of them are free. The data also sit closer to their own mean than to the true population mean, so dividing the squared deviations by n would underestimate the population variance. Dividing by n − 1 (Bessel's correction) removes that bias in the variance.
Use pooled df (n₁ + n₂ − 2) only when you have good reason to believe the two population variances are equal. Otherwise use Welch's df. Welch loses very little power when variances happen to be equal and protects the error rate when they are not, so many analysts use it by default. Statistical software such as R does exactly that.
Yes. Welch's t-test produces non-integer df, such as 19.84, because it combines two separate variance estimates. Software uses the exact value. If you are reading a printed t table, round down to the next whole number, which gives a slightly larger critical value and errs on the cautious side. Pooled t, chi-square, ANOVA and regression df are always whole numbers.
For a test of independence, df = (rows − 1)(columns − 1). For a goodness-of-fit test, df = k − 1 − m, where k is the number of categories and m is the number of parameters estimated from the data. A 2 × 2 table therefore has 1 df. The total sample size does not enter the formula.
They are the two df values of an F distribution. In one-way ANOVA the numerator df is k − 1 (between groups) and the denominator df is N − k (within groups). In an F-test comparing two variances they are n₁ − 1 and n₂ − 1. Order matters: F(3, 24) and F(24, 3) have different critical values.
With p predictors and an intercept, model df = p, residual df = n − p − 1 and total df = n − 1. Simple linear regression has p = 1, so residual df = n − 2. The t-test for each coefficient uses the residual df, and the overall F-test uses (p, n − p − 1). Testing a Pearson correlation also uses n − 2.
Put df in parentheses after the test symbol. Examples: t(24) = 2.31, p = .030; χ²(6, N = 200) = 14.20, p = .027; F(3, 24) = 4.12, p = .017. For a Welch test, report the df with one or two decimals, for example t(19.84) = 2.10, p = .049. Report exact p-values unless p is below .001.
For the tests on this page, df must be at least 1. A df of 0 means you have as many estimated parameters as data points, so the variance cannot be estimated, as with a one-sample t-test on a single observation. A negative df means more parameters than observations, which makes the model unidentifiable. The calculator shows an error in those cases instead of a number.