Degrees of Freedom Calculator

Calculate degrees of freedom for one-sample t-tests, two-sample t-tests, chi-square independence, one-way ANOVA, and linear regression.

Science 5 tests ANOVA support
Rate this calculator · 5.0 (1)

Degrees of Freedom

5 test types · ANOVA F(df₁,df₂) · regression df

Instructions — Degrees of Freedom Calculator

Pick the statistical test you are running, enter sample sizes or table dimensions, and read the degrees of freedom.

  1. Select a test: one-sample t, two-sample t (pooled), chi-square independence, one-way ANOVA, or linear regression.
  2. Enter the required inputs: sample size n, group counts, table rows/columns, or predictor count.
  3. Read df. For ANOVA you get three values (between, within, total) and the resulting F-statistic form F(df1, df2).

Formulas

Each test has its own df formula. The pattern is always: df = (independent observations) − (parameters estimated).

One-sample t-test: $$ df = n - 1 $$ One mean is estimated, so one constraint.

Two-sample t-test (pooled): $$ df = n_1 + n_2 - 2 $$ Two means estimated.

Chi-square (independence): $$ df = (r - 1)(c - 1) $$ Row and column totals fix the marginals.

One-way ANOVA: $$ df_{\text{between}} = k - 1, \quad df_{\text{within}} = N - k, \quad df_{\text{total}} = N - 1 $$ The F-statistic uses both: $F \sim F(k-1, N-k)$.

Linear regression (residual): $$ df = n - p - 1 $$ Subtract p predictors plus 1 intercept.

Reference

For a two-tailed test at α = 0.05:

dftcrit
52.571
102.228
202.086
302.042
502.009
1001.984
1.960 (normal)

Higher df means narrower confidence intervals and a smaller critical value. As df → ∞, the t-distribution converges to the standard normal.

Article — Degrees of Freedom Calculator

Degrees of Freedom Calculator: df Formulas for t, χ2, ANOVA, and Regression

Degrees of freedom (df) is the number of independent values in a statistical calculation. For a one-sample t-test, df = n − 1. For a two-sample pooled t-test, df = n1 + n2 − 2. For a chi-square test of independence on an r-by-c table, df = (r − 1)(c − 1). The degrees of freedom calculator handles t-tests, chi-square, one-way ANOVA, and linear regression.

Degrees of freedom determines the exact shape of test statistics' distributions. Two t-tests with the same observed t-value can yield different p-values purely because of different df. Getting df right is a routine but essential step in hypothesis testing.

What degrees of freedom mean

When statisticians estimate a parameter from a sample, the last data point becomes constrained by the estimate. If five numbers must average exactly 10 (because you computed their sample mean to be 10), four of them are free to take any value, but the fifth is forced by the constraint. That gives 4 degrees of freedom, not 5.

The general rule is: degrees of freedom = (independent observations) − (parameters estimated). Each estimated parameter eats one df. One-sample t-tests estimate one mean and lose one df; two-sample tests estimate two means and lose two.

Building intuition for degrees of freedom

A common analogy: imagine choosing five numbers whose sum must equal 250 (because their mean is 50). You can pick the first four freely: 30, 60, 80, 55. The fifth is forced: 250 − 30 − 60 − 80 − 55 = 25. Four free choices, one constraint, df = 4.

The same logic explains why sample variance divides by n − 1 instead of n. The deviations from the sample mean must sum to zero (a constraint imposed by computing the mean from the data), so only n − 1 of them are independent. Bessel's correction (dividing by n − 1) makes the variance estimator unbiased.

Did you know

R. A. Fisher introduced the concept of degrees of freedom in the 1920s when developing the modern theory of the t-distribution. William Sealy Gosset, writing under the pseudonym "Student" while working at Guinness Brewery in 1908, had discovered the distribution empirically but did not fully understand why its shape depended on sample size. Fisher's insight — that degrees of freedom shape the distribution — closed the gap and put small-sample statistics on a rigorous footing.

Degrees of freedom by test type

Degrees of freedom formulas
One-sample t df = n − 1
Two-sample t (pooled) df = n₁ + n₂ − 2
Chi-square (r × c) df = (r − 1)(c − 1)
ANOVA between df = k − 1
ANOVA within df = N − k
Linear regression df = n − p − 1

The patterns repeat: subtract one for each parameter estimated from the data. The variations come from how many parameters each model needs.

Degrees of freedom in t-tests

A one-sample t-test compares a sample mean to a known reference. Only the sample mean is estimated, so df = n − 1. With n = 25, df = 24.

A two-sample pooled t-test estimates two means and assumes equal variances. df = n1 + n2 − 2. With group sizes 20 and 18, df = 36.

Welch's t-test (for unequal variances) uses a more complex df formula that yields a non-integer value, somewhere between min(n1, n2) − 1 and n1 + n2 − 2. Most statistics software computes this automatically; the calculator above uses the simpler pooled formula.

Degrees of freedom in chi-square

A chi-square test of independence uses a contingency table with r rows and c columns. The row and column totals (marginal totals) are fixed by the data, which constrains the cells. The number of free cells is (r − 1)(c − 1).

For a 2×2 table, df = 1. For 3×4, df = 6. The same df formula applies for the chi-square goodness-of-fit test with k categories: df = k − (number of parameters fit from the data) − 1.

Degrees of freedom in ANOVA

One-way ANOVA partitions variance into between-group and within-group components, each with its own df.

dfbetween = k − 1, where k is the number of groups. dfwithin = N − k, where N is the total sample size. dftotal = N − 1, equal to the sum of the other two.

The F-statistic in ANOVA is F = MSbetween / MSwithin, where MS = SS / df for each source. The resulting F follows an F-distribution with parameters (dfbetween, dfwithin). Both numbers appear in F-tables when looking up critical values.

Degrees of freedom in regression

In linear regression with n observations and p predictors plus an intercept, residual df = n − p − 1. Each predictor and the intercept consume one df. Model df = p, and total df = n − 1.

The t-statistics for each regression coefficient follow a t-distribution with n − p − 1 df. F-tests for nested models use the difference in degrees of freedom between the full and reduced models. When n is close to p, df shrinks toward zero and the model becomes unreliable; this is why a rule of thumb is at least 10–20 observations per predictor.

How degrees of freedom affect conclusions

Same test statistic, different p-value

Two t-tests with the same observed t = 2.5 can yield different p-values purely because of different df. With df = 5, p ≈ 0.054; with df = 100, p ≈ 0.014. The size of the sample changes the certainty associated with the same observed effect. Always report df alongside any test statistic.

  • Larger df = narrower confidence intervals: as df → ∞, t-critical → 1.96 (normal distribution)
  • Smaller df = fatter tails: more extreme values are less surprising with small samples
  • df cannot be zero or negative: that signals an unidentified model (more parameters than data)
  • df is reported alongside test statistics in publications: e.g., t(24) = 2.1 or F(3, 76) = 5.4
  • Rough rule for regression: at least 10–20 observations per predictor for reliable inference

For a two-tailed t-test at α = 0.05, the critical t-value drops from 2.571 at df = 5 to 2.228 at df = 10, 2.042 at df = 30, and 1.984 at df = 100. As df grows, the t-distribution approaches the standard normal, and the small-sample correction becomes negligible.

Tip

When in doubt, report both the test statistic and its degrees of freedom: t(24) = 2.07, p = 0.049 is clearer than "t = 2.07, p = 0.049." A reviewer can verify your calculation and assess whether the sample was large enough to support the claim.

FAQ

The number of independent values in a calculation. When you estimate a parameter (such as a mean) from data, the last data point becomes constrained by the estimate, so one degree of freedom is lost. For n data points and one estimated mean, df = n − 1.
Dividing by n − 1 (Bessel's correction) accounts for the one degree of freedom lost to estimating the sample mean. Dividing by n underestimates the population variance; dividing by n − 1 makes the estimator unbiased.
For a pooled two-sample t-test, df = n1 + n2 − 2. Two sample means are estimated, so two degrees are lost. Welch's t-test (unequal variances) uses a more complex formula that approximates df with a non-integer value.
Df defines the shape of the test statistic's distribution. For the same observed t- or F-value, smaller df gives a larger p-value (fatter tails), and larger df gives a smaller p-value. With df > ~100, the t-distribution is effectively normal.
No. Zero or negative df means you have more parameters than independent observations — the model is unidentified. If you see df ≤ 0, reduce the number of predictors or collect more data.
One-way ANOVA splits df into dfbetween = k − 1 and dfwithin = N − k, where k is the number of groups and N is the total sample size. The F-statistic is F(dfbetween, dfwithin); both values appear in the F-table to find the critical value.
For an r-by-c contingency table, df = (r − 1)(c − 1). The row and column totals constrain the table, so only that many cells are free to vary. For a 3-by-4 table, df = 2 × 3 = 6.
Residual df = n − p − 1, where n is the sample size and p is the number of predictors. Subtract 1 extra for the intercept. The model df equals p, and the total df is n − 1 (model df + residual df).