BY: Statistics Fundamentals Team
Reviewed By: Minsa A (Senior Statistics Editor)
Last updated:

Degrees of Freedom Calculator

Find the degrees of freedom (df) for a one-sample, paired or two-sample t-test (pooled or Welch), a chi-square test, one-way or two-way ANOVA, an F-test or a regression. Pick the test, enter your sample sizes, and the calculator returns df, the matching critical value and the full working. It runs in your browser and needs no signup.

Degrees of Freedom Calculator

Formula df = n − 1 Use for One-sample and paired t-tests
For a paired test, enter the number of pairs.
Formula df = n₁ + n₂ − 2  or  Welch–Satterthwaite Use for Independent two-sample t-tests
Required for Welch.
Required for Welch.
Formula (r − 1)(c − 1)  or  k − 1 − m Use for Chi-square tests
Formula k − 1, N − k, N − 1 Use for One-way and two-way ANOVA
Formula df₁ = n₁ − 1, df₂ = n₂ − 1 Use for Comparing two variances
Formula n − p − 1 Use for Regression and correlation
Not counting the intercept. Use 1 for simple regression or a Pearson correlation test.

Run a calculation in any of the other tabs first, then return here to see the full step-by-step solution.

No data yet. Enter values in any test tab first.

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 seeAlso writtenWhat it means
N − 2 (two-sample t)n₁ + n₂ − 2N is the total across both groups, so N = n₁ + n₂. Identical value.
n − 2 (regression)n − p − 1 with p = 1Simple regression is the one-predictor case of the general formula.
Model / error / totalRegression / residual / total, or between / within / totalDifferent 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.
dfd.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.

1
Identify the test and what it estimates

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.

2
Count the independent observations

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.

3
Subtract the estimated parameters

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.

4
Look up the critical value

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

Scenarion₁ / s₁n₂ / s₂Pooled dfWelch df
Equal SDs, equal n20 / 520 / 53838.00
Second SD twice as large20 / 520 / 103827.94
Second SD four times as large20 / 520 / 203821.37
Noisier group is the small one10 / 840 / 44810.15
Noisier group is the large one10 / 440 / 84829.25
Worked example below12 / 4.215 / 9.82519.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

Scenario: Class A has n₁ = 12 and s₁ = 4.2. Class B has n₂ = 15 and s₂ = 9.8. Find the Welch df.
Variance of each mean

s₁²/n₁ = 4.2² / 12 = 1.4700  |  s₂²/n₂ = 9.8² / 15 = 6.4027  |  sum = 7.8727

Numerator

(sum)² = 7.8727² = 61.979

Denominator

1.4700²/11 = 0.1964  |  6.4027²/14 = 2.9282  |  sum = 3.1246

Welch df

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

SourceFormulaOne-way (k = 4, N = 28)Two-way (3 × 4, r = 5)
Between groups / Factor Ak − 1  or  a − 132
Factor Bb − 1n/a3
Interaction A × B(a − 1)(b − 1)n/a6
Within groups / ErrorN − k  or  ab(r − 1)2448
TotalN − 1  or  abr − 12759

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)

df95% (α = 0.05)99% (α = 0.01)95% cutoff vs z
112.70663.657+548.3%
24.3039.925+119.5%
33.1825.841+62.4%
52.5714.032+31.2%
102.2283.169+13.7%
202.0862.845+6.4%
302.0422.750+4.2%
602.0002.660+2.1%
1201.9802.617+1.0%
∞ (normal z)1.9602.5760%

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
13.8416.635
25.9919.210
37.81511.345
49.48813.277
511.07015.086
612.59216.812
815.50720.090
1018.30723.209
1524.99630.578
2031.41037.566

Table: F critical values, α = 0.05 (right tail)

Numerator dfDenominator dfF*
1104.965
2203.493
3243.009
4302.690
5402.449
3103.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

ScenarioCalculationdfCritical value
Coffee shop times 25 espresso shots (one-sample t)n − 1 = 25 − 124±2.064
18 runners timed before and after training (paired t)pairs − 1 = 18 − 117±2.110
Two classes, 12 and 15 students, equal variances (pooled t)n₁ + n₂ − 2 = 12 + 15 − 225±2.060
Same classes, SDs of 4.2 and 9.8 (Welch t)Welch–Satterthwaite19.84±2.087
Survey answers by 3 age bands and 4 regions (independence)(3 − 1)(4 − 1)612.592
Poisson fit to 6 count categories, λ estimated (goodness of fit)6 − 1 − 149.488
4 diets, 28 participants (one-way ANOVA)k − 1 = 3, N − k = 243 and 243.009
50 homes, 3 predictors (regression)n − p − 1 = 50 − 3 − 146±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 within

Python

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 - 1

Excel

=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)

TestFormatExample
One-sample or paired tt(df) = value, p = valuet(24) = 2.31, p = .030
Welch tt(df) = value, p = valuet(19.84) = 2.10, p = .049
Pearson correlationr(df) = value, p = valuer(48) = .35, p = .013
Chi-squareχ²(df, N = total) = value, p = valueχ²(6, N = 200) = 14.20, p = .027
ANOVAF(df between, df within) = value, p = valueF(3, 24) = 4.12, p = .017
Regression, overallF(df model, df residual) = value, p = valueF(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.

MistakeWhy it is wrongCorrect approach
Using n for a one-sample t-testThe mean is estimated from the same data, which costs one df.df = n − 1
Treating paired data as two samplesEach pair gives one difference. 18 pairs have 17 df, not 34.df = pairs − 1
Pooled df with unequal variancesIt overstates the information when one group is much noisier.Use Welch's df
Rounding Welch df upA 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 sizedf depends on the table's dimensions, not on how many people are in it.(r − 1)(c − 1)
Ignoring fitted parameters in goodness of fitA Poisson mean or normal SD estimated from the data uses up df.k − 1 − m
Swapping numerator and denominator dfThe F distribution is not symmetric in its two df.F(df between, df within)
Forgetting the intercept in regressionThe 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.

TermSymbol / FormulaPlain-English DefinitionPrimary Use
Degrees of freedomdf = n − (estimated parameters)Number of values free to vary after constraints are appliedChoosing the t, χ² or F distribution
ConstraintΣ(x − x̄) = 0A condition the data must satisfy, such as deviations summing to zeroCounting free values
Estimated parameterx̄, b₀, b₁, λA quantity calculated from the sample and then reused in the testSubtracted from n to get df
Bessel's corrections² = Σ(x − x̄)² / (n − 1)Dividing by n − 1 so the sample variance is unbiasedSample variance and SD
Welch–Satterthwaite equationdf = (s₁²/n₁ + s₂²/n₂)² / …Approximate df for a standard error built from two separate variancesWelch's t-test
Residual dfn − p − 1Observations left after estimating all regression coefficientst-tests on coefficients
Numerator dfk − 1  or  df₁df of the variance estimate on top of the F ratioF table lookup
Denominator dfN − k  or  df₂df of the variance estimate on the bottom of the F ratioF table lookup
Critical valuet*, χ²*, F*The cutoff a test statistic must pass at a chosen α and dfHypothesis test decisions
t distributiont(df)Bell-shaped, heavier tails than the normal when df is smallMeans with unknown σ
Chi-square distributionχ²(df)Right-skewed distribution of a sum of squared standard normalsCounts and categorical data
F distributionF(df₁, df₂)Distribution of a ratio of two variance estimatesANOVA and variance tests
Contingency tabler × cGrid of counts cross-classified by two categorical variablesChi-square independence test
Mean squareMS = SS / dfA sum of squares divided by its df, giving a variance estimateANOVA 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:

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.