Skip to main content
v2026.11,986 entries · CC-BY 4.0

Analysis of Variance Degrees of Freedom: df Formulas and a Worked Example

Between, within and total degrees of freedom in one-way and two-way ANOVA, with a worked numeric example and how to report F(df1, df2).

Written and maintained by CASRAI Editorial Board

Published

On this page

In a one-way analysis of variance with k groups and N observations in total, the degrees of freedom are k − 1 between groups, N − k within groups (error) and N − 1 in total. The F statistic is the ratio of two mean squares, so it always carries two degrees of freedom: the numerator df (k − 1) and the denominator df (N − k). You need both to look up a critical value or to report the result as F(df₁, df₂).

What degrees of freedom mean in ANOVA

ANOVA splits the total variation in a data set into a part explained by the grouping factor (treatments) and a part left over as error. Each sum of squares is divided by its degrees of freedom to give a mean square, which is a variance estimate. Degrees of freedom count how many independent pieces of information go into each sum of squares: the group means can vary freely except that they must be consistent with the grand mean, and each observation can vary around its own group mean except that the deviations within a group must sum to zero.

The model behind the one-way table writes each observation as Yij = μ + τi + εij, with errors assumed independent and normally distributed with constant variance (NIST/SEMATECH e-Handbook, section 7.4.3.2). The degrees of freedom follow from that structure.

Analysis of variance degrees of freedom formulas

The NIST/SEMATECH e-Handbook (section 7.4.3.3) lays out the one-way ANOVA table as follows. Every symbol is defined below the list.

  • Treatments (between groups): df = k − 1; MST = SST / (k − 1)
  • Error (within groups): df = N − k; MSE = SSE / (N − k)
  • Total (corrected): df = N − 1
  • Test statistic: F = MST / MSE

k is the number of groups (levels of the factor), N is the total number of observations across all groups (the sum of the group sizes ni), SST is the treatment sum of squares, SSE is the error sum of squares, MST and MSE are the corresponding mean squares. The identity (k − 1) + (N − k) = N − 1 always holds, which gives you a quick arithmetic check on any ANOVA table.

Why F has two degrees of freedom

F is a ratio of two independent variance estimates, and each estimate has its own degrees of freedom. The numerator (MST) uses k − 1 and the denominator (MSE) uses N − k. The F distribution is therefore a family indexed by the pair (df₁, df₂), and the critical value for a given significance level α is read from the table row and column for that pair. The test rejects the hypothesis of equal group means when the computed F exceeds that tabular value (NIST/SEMATECH, section 7.4.3.3).

Worked example: calculating each df step by step

The NIST handbook illustrates one-way ANOVA with resistor readings taken at three temperatures, five readings each. The data are: level 1 = 6.9, 5.4, 5.8, 4.6, 4.0 (mean 5.34); level 2 = 8.3, 6.8, 7.8, 9.2, 6.5 (mean 7.72); level 3 = 8.0, 10.5, 8.1, 6.9, 9.3 (mean 8.56).

  1. Count groups and observations. k = 3 groups, ni = 5 each, so N = 3 × 5 = 15.
  2. Between-groups df. k − 1 = 3 − 1 = 2.
  3. Within-groups df. N − k = 15 − 3 = 12.
  4. Total df. N − 1 = 15 − 1 = 14. Check: 2 + 12 = 14.
  5. Sums of squares. The grand total is 108.1, so the grand mean is 108.1 / 15 = 7.2067. SST = 27.897 and SSE = 17.452, giving a total of 45.349.
  6. Mean squares. MST = 27.897 / 2 = 13.949. MSE = 17.452 / 12 = 1.454.
  7. F statistic. F = 13.949 / 1.454 = 9.59.
  8. Critical value. For α = 0.05 with 2 and 12 degrees of freedom, the critical F is 3.89. Because 9.59 > 3.89, the equal-means hypothesis is rejected; the exact p-value is about 0.0032.
Source SS df MS F
Treatments 27.897 2 13.949 9.59
Error 17.452 12 1.454
Total (corrected) 45.349 14

Sums of squares, mean squares and F reproduce the NIST table; the p-value and the critical value 3.89 were recomputed from the F distribution with 2 and 12 degrees of freedom (critical value 3.885 before rounding).

Interpreting the degrees of freedom and the F result

What you see How to read it
Numerator df = k − 1 Tells you how many groups were compared: df₁ = 2 means three groups.
Denominator df = N − k Reflects how much information estimates the error variance; here 12 for 15 observations in 3 groups. More error df means a tighter critical value.
F larger than the critical value for (df₁, df₂) Reject equal means at that α. Here 9.59 exceeds 3.89.
df₁ + df₂ ≠ total df The identity (k − 1) + (N − k) = N − 1 is broken, so a count is wrong.
Significant F At least one group mean differs; it does not say which. Follow-up comparisons are needed.

For the example, the proportion of total variation explained by temperature is SST / SStotal = 27.897 / 45.349 ≈ 0.62 (an eta-squared computed from the table above).

Two-way ANOVA degrees of freedom

With two factors A (a levels) and B (b levels) and r replicates per cell, the balanced design has N = a × b × r observations. NIST section 7.4.3.7 gives: factor A df = a − 1, factor B df = b − 1, interaction AB df = (a − 1)(b − 1), error df = N − ab, total df = N − 1. For its example with a = 3, b = 4 and r = 2 (N = 24) these are 2, 3, 6, 12 and a total of 23, and 2 + 3 + 6 + 12 = 23. The error df is N − ab rather than N − k because the model now estimates one mean per cell (ab cells), not one per group. For a side-by-side view of the two designs see one-way vs two-way ANOVA; the data table below collects both sets of formulas with the numeric examples.

Assumptions and common mistakes

  • Using N instead of k. The numerator df is k − 1 (groups), not N − 1. Confusing the two is the most frequent counting slip.
  • Miscounting groups. Count the levels of the factor, not the number of participants per level.
  • Reporting only one df. F needs both: F(2, 12), not F(12).
  • Using the one-way error df in a two-way design. Use N − ab (balanced case) and remember the interaction term has its own df.
  • Ignoring assumptions. The F test relies on independent observations, normally distributed errors and equal error variances across groups (NIST section 7.4.3.2). Degrees of freedom do not repair a violated assumption.
  • Reading a significant F as a pairwise finding. It only says the group means are not all equal.

How to report ANOVA degrees of freedom (APA style)

Report the F statistic with both degrees of freedom in parentheses, then the exact p-value. For the example: F(2, 12) = 9.59, p = .003. Adding an effect size is good practice, for instance η² = .62. Italicise the statistical symbols. See also the ANOVA dictionary entry and the guide to types of test statistics.

How to calculate ANOVA degrees of freedom in Excel, R or Python

Excel

Degrees of freedom are not computed for you by a formula; derive them from the counts, then use the F functions. With k = 3 and N = 15 in cells, df₁ = k − 1 and df₂ = N − k:

=F.DIST.RT(9.59, 2, 12)     returns the p-value (about 0.0032)
=F.INV.RT(0.05, 2, 12)      returns the critical F (about 3.89)

The Data Analysis ToolPak option “Anova: Single Factor” prints the df column directly. See statistical analysis in Excel.

R

y <- c(6.9,5.4,5.8,4.6,4.0, 8.3,6.8,7.8,9.2,6.5, 8.0,10.5,8.1,6.9,9.3)
g <- factor(rep(c("L1","L2","L3"), each = 5))
summary(aov(y ~ g))     # Df column: 2 and 12
qf(0.95, 2, 12)         # critical value
pf(9.59, 2, 12, lower.tail = FALSE)  # p-value

Python

from scipy import stats
l1=[6.9,5.4,5.8,4.6,4.0]; l2=[8.3,6.8,7.8,9.2,6.5]; l3=[8.0,10.5,8.1,6.9,9.3]
F, p = stats.f_oneway(l1, l2, l3)       # F about 9.59
k, N = 3, 15
df1, df2 = k - 1, N - k                 # 2, 12
crit = stats.f.ppf(0.95, df1, df2)      # about 3.89

FAQ

What are the degrees of freedom for a one-way ANOVA?

Between groups k − 1, within groups N − k, total N − 1, where k is the number of groups and N the total sample size.

How do I find degrees of freedom for an F test in ANOVA?

Numerator df is the between-groups df (k − 1) and denominator df is the within-groups df (N − k). Use that pair to read the critical F value.

Why is the within-groups df N − k?

Each of the N observations contributes information, but k group means were estimated from the data, which uses up k degrees of freedom.

Can the degrees of freedom be non-integers?

In the standard equal-variance one-way ANOVA the df are whole numbers. Corrected procedures for unequal variances use adjusted, fractional df; that is outside the standard table above.

How many degrees of freedom does a two-way ANOVA have?

(a − 1) for factor A, (b − 1) for factor B, (a − 1)(b − 1) for the interaction, N − ab for error and N − 1 in total in a balanced design.

Sources

Data: ANOVA degrees of freedom formulas and worked numeric examples (one-way and two-way)

Degrees-of-freedom formulas for each source of variation in balanced one-way and two-way ANOVA with the numeric values for the NIST/SEMATECH worked examples, compiled from the NIST e-Handbook ANOVA sections.

ANOVA degrees of freedom formulas and worked numeric examples (one-way and two-way)
Design and source of variationFormulaExample df
One-way: treatments (between)k - 12
One-way: error (within)N - k12
One-way: totalN - 114
Two-way: factor Aa - 12
Two-way: factor Bb - 13
Two-way: interaction AB(a - 1)(b - 1)6
Two-way: errorN - ab12
Two-way: totalN - 123

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Analysis of Variance Degrees of Freedom: df Formulas and a Worked Example

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →