Degrees of Freedom Calculator

Calculate degrees of freedom for any statistical test. Enter your sample sizes and parameters, and see the exact formula with your numbers substituted in.

DF
DF BETWEEN
DF WITHIN
DF TOTAL
DF REGRESSION
DF RESIDUAL
Enter your sample size(s) and parameters to calculate degrees of freedom.

    §1 Reference: Degrees of Freedom Formulas

    Every statistical test has a unique degrees of freedom formula. Use this table to find the formula for your test, or see the "How this was calculated" section above for your specific numbers.

    Test Formula What it means
    One-sample t-test df = n − 1 Number of observations minus 1, because you estimated the sample mean.
    Independent t-test
    (equal variances)
    df = n₁ + n₂ − 2 Combined sample size minus 2 (one for each estimated mean).
    Welch t-test
    (unequal variances)
    df = (s₁²/n₁ + s₂²/n₂)² ÷ [(s₁²/n₁)²/(n₁−1) + (s₂²/n₂)²/(n₂−1)] Satterthwaite approximation; accounts for unequal variances. Result is typically fractional.
    Paired t-test df = n − 1 Number of pairs minus 1 (applies to the differences, not the raw data).
    One-way ANOVA df between = k − 1
    df within = N − k
    df total = N − 1
    Between = groups minus 1. Within = total observations minus groups. Total = sum of between and within.
    Chi-square test of
    independence
    df = (r − 1)(c − 1) Rows minus 1, times columns minus 1. Equals the number of cells you can fill freely.
    Chi-square goodness
    of fit
    df = k − 1 − m Categories minus 1, minus the number of parameters you estimated from the data (usually 0).
    Simple linear
    regression
    df regression = 1
    df residual = n − 2
    df total = n − 1
    Regression always has 1 degree of freedom (one predictor). Residual = total minus regression. Total = n minus 1.

    Welch's degrees of freedom is fractional — keep the decimal

    The Welch–Satterthwaite formula produces a non-integer result. Do not round or floor it. Modern statistical software (R, SPSS, Python) all accept fractional degrees of freedom. Your calculator above will show the exact decimal value, which is what you use for critical values and p-values.

    §2 Worked Example: Welch's t-test Degrees of Freedom

    Welch's test is the one most students struggle with by hand, because the formula looks complex. Here's a complete worked example.

    Setup

    You have two independent groups with unequal variances:

    • Sample 1: n₁ = 12, s₁ = 3.5
    • Sample 2: n₂ = 8, s₂ = 2.1

    Calculation

    Step 1: Calculate the numerator. This is the squared sum of the variance components:

    numerator = (s₁²/n₁ + s₂²/n₂)²

    Substitute:

    numerator = (3.5²/12 + 2.1²/8)²

    Simplify:

    numerator = (12.25/12 + 4.41/8)² = (1.0208 + 0.5513)² = (1.5721)² = 2.4716

    Step 2: Calculate the denominator. This is the weighted sum of squared variance components, each divided by its degrees of freedom:

    denominator = (s₁²/n₁)²/(n₁−1) + (s₂²/n₂)²/(n₂−1)

    Substitute:

    denominator = (1.0208)²/(12−1) + (0.5513)²/(8−1)

    Simplify:

    denominator = 1.0420/11 + 0.3039/7 = 0.0947 + 0.0434 = 0.1381

    Step 3: Divide.

    df = 2.4716 / 0.1381 = 17.90

    The degrees of freedom for this Welch t-test is 17.90 (not rounded to 18). Use this value to look up your critical t-value or calculate your p-value.

    §3 Assumptions & When These Tests Apply

    One-sample t-test

    Assumes observations are independent, from a normal distribution (or n is large). The formula df = n − 1 does not change; what matters is whether the test is valid for your data.

    Independent t-test with equal variances

    Assumes both groups are sampled from normal distributions with equal population variances. If variances are unequal, use Welch's test instead. This test is less common in practice than Welch's.

    Welch's t-test (unequal variances)

    Assumes normal distributions but does not assume equal variances. This is the safer default when you are uncertain. The Satterthwaite degrees of freedom is slightly lower than the pooled formula, reflecting the cost of not assuming equal variances.

    Paired t-test

    Assumes the differences (not the raw values) are approximately normal, and observations are independent. The degrees of freedom are based on the number of pairs, not the number of individual values.

    One-way ANOVA

    Assumes observations are independent, groups are normally distributed with equal variances, and groups are random samples. The "between" degrees of freedom = k − 1 only depends on the number of groups; the "within" degrees of freedom = N − k depends on total sample size and group count.

    Chi-square tests

    For independence: assumes independent observations with a large enough sample (expected frequencies ≥ 5 in most cells). For goodness of fit: assumes you know the expected frequencies (or can estimate them from the data). The degrees of freedom reflect the number of cell counts you can choose freely before the rest are determined by row and column totals.

    Simple linear regression

    Assumes observations are independent, the relationship is linear, and residuals are normally distributed with constant variance. The degrees of freedom are fixed: 1 for regression (one slope), n − 2 for residuals (n observations minus 2 parameters: intercept and slope).

    §4 FAQ

    What are degrees of freedom in plain English?

    Degrees of freedom is the number of values in a calculation that are free to vary. If you know the total of a set of numbers and all but one of them, the last one is fixed — you have lost one degree of freedom. In statistics, every time you estimate a parameter (like a mean), you lose one degree of freedom, because that constraint reduces the number of independent pieces of information left in your data.

    Why is it n − 1 and not n?

    Because you used one piece of information from your sample (the sample mean) to set up the test. Once you know the mean and all but one of the values, the last value is determined. So you have n − 1 independent pieces of information left. This is why the t-distribution with df = n − 1 is fatter (has heavier tails) than the normal distribution—it accounts for the extra uncertainty of estimating the mean from a small sample.

    What are degrees of freedom for a chi-square test?

    In a chi-square test, degrees of freedom equals the number of cell frequencies you can fill in freely before the rest are determined by the row and column totals. For independence tests: df = (rows − 1) × (columns − 1). For goodness of fit: df = (categories − 1) − (parameters estimated from data). The intuition is the same: each constraint (knowing a total, estimating a parameter) reduces the degrees of freedom by 1.

    What are degrees of freedom for ANOVA?

    In one-way ANOVA, there are two degrees of freedom: between-groups df = k − 1 (number of groups minus 1), and within-groups df = N − k (total observations minus number of groups). The between-groups df reflects how many group means you can set freely; the within-groups df reflects the independent variability left after accounting for group membership. They sum to N − 1, the total degrees of freedom.

    Why is Welch's degrees of freedom not a whole number?

    Welch's t-test uses the Satterthwaite approximation to compute degrees of freedom, which accounts for unequal variances by weighting each sample's contribution separately. This weighted calculation typically produces a decimal value. That's not a sign of an error—modern software handles fractional degrees of freedom precisely, using the continuous gamma function to evaluate the t-distribution. The result is often more accurate than rounding to the nearest integer.

    Do I need to memorize these formulas?

    No. The point of this calculator is to help you understand and apply the right formula to your data. What matters is knowing which test is appropriate for your research question. Once you pick the test, the formula is something you can look up (or use a tool like this). What you should remember is the conceptual idea: degrees of freedom = sample size minus the number of parameters you estimated.

    §5 Cross-linked Tools

    Degrees of freedom are a building block for several other calculations:

    §6 Sources