Degrees of Freedom Calculator (df) – t, Chi Square, ANOVA

Free degrees of freedom calculator finds df for t-tests, chi square, ANOVA & regression. Every formula, step-by-step, plus a full df reference table.

Degrees of Freedom Calculator

Degrees of freedom is the number of values free to vary after constraints: df = observations − constraints. Pick your test, enter your numbers, and the calculator shows the right formula and every step.

Degrees of freedom (df) is the number of values in a calculation that are free to vary once you apply the constraints of your test. The short rule is df = observations minus constraints. For a one-sample t test with 20 values, df = 20 – 1 = 19. The formula shifts by test type, and this page walks through every one with worked numbers and a full reference table you can scan in seconds.

What Is Degrees of Freedom?

Degrees of freedom, written as df, tells you how many values in a calculation are free to vary after the fixed quantities are set.

Here is the plain version. Say you have 5 numbers and you already know their average. Four of those numbers can be anything, but once four are chosen, the fifth is locked in place to keep that average true. So the degrees of freedom is 4, not 5.

That single idea runs through most of statistics. You use degrees of freedom when calculating variance, standard deviation, t-tests, chi-square tests, regression, and ANOVA. Each test estimates something from the data (usually a mean), and every estimate costs you information. Degrees of freedom is the accounting for what is left.

The general rule most people remember is this:

Degrees of freedom = number of observations – number of constraints

For sample variance and one-sample tests, the constraint is the single estimated mean. That is exactly why sample variance divides by n – 1 instead of n.

Is Degrees of Freedom Always n – 1?

No. df = n – 1 is only the one-sample case. It is the version most textbooks show first, so people assume it always applies, but it does not.

The n – 1 rule holds when you estimate a single parameter (the mean) from one sample. The moment your test estimates more quantities or works with a table, the formula changes:

  • One sample, one mean estimated: df = n – 1
  • Two samples, two means estimated: df = n₁ + n₂ – 2
  • Chi-square table: df depends on rows and columns, not on n
  • Regression: df = n – k – 1, because each predictor and the intercept each cost one

So the honest answer is that df is always observations minus the number of things you estimated. Sometimes that lands on n – 1, often it does not.

Degrees of Freedom Formula by Test Type

Every formula below comes from the same rule: start with your observations, subtract one for each quantity estimated from the same data. This table is the fast reference.

Testdf formulaWorked exampleResult
1-sample t-testdf = n – 1n = 2019
2-sample t-test (equal variances)df = n₁ + n₂ – 215 and 1831
2-sample t-test (Welch, unequal)Welch-Satterthwaite equationusually a decimal19.19
Chi-square, goodness of fitdf = k – 1k = 5 categories4
Chi-square, independencedf = (r – 1)(c – 1)3 × 4 table6
ANOVA, between groupsdf = k – 1k = 3 groups2
ANOVA, within groupsdf = N – kN = 30, k = 327
ANOVA, totaldf = N – 1N = 3029
Regressiondf = n – k – 1n = 25, k = 222

Pick your test in the calculator above and it applies the matching formula and shows each step, so you never have to guess which one fits.

How to Find Degrees of Freedom Step by Step

Start with your number of observations, then subtract one for every quantity you estimated from that same data. Here is how that plays out for each common test.

One-sample t-test: df = n – 1

With 20 values, df = 19. You subtract one because the sample mean was estimated from those same 20 numbers.

Two-sample t-test, equal variances: df = n₁ + n₂ – 2

With samples of 15 and 18, df = 15 + 18 – 2 = 31. Two means were estimated, so two are subtracted. This is also the answer for the common search “degrees of freedom calculator for two independent samples,” as long as you assume equal variances.

Two-sample t-test, unequal variances (Welch)

When the two groups have clearly different spread, the pooled formula overstates your df. The Welch-Satterthwaite equation corrects for it and almost always returns a decimal. Do not round it before finding your p value. The calculator above handles the full equation for you and also shows the pooled df next to it for comparison.

Chi-square, independence: df = (rows – 1)(columns – 1)

A 3 by 4 contingency table gives df = (3 – 1)(4 – 1) = 6. Here the constraint is the row and column totals, not how many observations you collected.

Chi-square, goodness of fit: df = k – 1

Five categories give df = 5 – 1 = 4. If you also estimated a parameter from the data (like a mean for a Poisson fit), subtract one more for each estimate.

One-way ANOVA: split into three

With 30 observations across 3 groups: between-groups df = 3 – 1 = 2, within-groups df = 30 – 3 = 27, total df = 30 – 1 = 29. Notice 2 + 27 = 29, which is the built-in check. An ANOVA test needs both the between and within numbers for its F ratio.

Regression: df = n – k – 1

With 25 observations and 2 predictors, df = 25 – 2 – 1 = 22. You lose one df per predictor plus one for the intercept.

What Are df Between, df Within, and df Total in ANOVA?

ANOVA does not give you one degrees of freedom number. It gives you three, and each answers a different question.

  • df between (numerator): df = k – 1, where k is the number of groups. It measures the variation among group means.
  • df within (denominator): df = N – k, where N is the total observations. It measures variation inside the groups.
  • df total: df = N – 1. It should equal df between plus df within, which is a quick way to check your work.

The F test reports these as a pair, written like F(2, 27). The first number is df between, the second is df within. If those two do not add up to df total, one of your inputs is off.

How Do You Find Degrees of Freedom in Excel?

Excel does not have a single DF function, because df depends on the test. You either compute it directly or pull it from the tools that use it.

  • One sample: if your data sits in A2:A21, type =COUNT(A2:A21)-1 to get n – 1.
  • Two samples, equal variances: =COUNT(A:A)+COUNT(B:B)-2.
  • Chi-square: multiply (rows – 1) by (columns – 1) in a plain formula, for example =(3-1)*(4-1).
  • From a t-test output: Excel’s Data Analysis ToolPak reports df directly in the t-test results table, so you do not have to calculate it by hand.

For Welch’s df, the Excel formula gets long and easy to mistype. That is the case where this calculator is faster and less error-prone than a spreadsheet.

Why Degrees of Freedom Matter in Hypothesis Testing

Degrees of freedom control how strict a test is. They directly shape the critical value, the p-value, and the shape of the reference distribution. Get df wrong and your conclusion can flip.

  • p-values depend on df. Your test statistic is compared against a distribution that changes with df. A smaller df gives a wider distribution and more cautious results.
  • Critical values depend on df. t-tests, chi-square, and ANOVA all read their cutoff from a df-indexed table. Wrong df, wrong cutoff.
  • Conclusions depend on df. Hypothesis testing is built on probability, and df defines how much independent information you actually have.

Common Mistakes When Calculating Degrees of Freedom

The formula looks simple, which is exactly why small slips are common. These are the ones that trip people up most.

  • Using the wrong test’s formula. Applying a t-test rule to a chi-square or ANOVA problem is the most frequent error. Match the formula to the test first.
  • Forgetting the minus one. Sample-based tests almost always cost you at least one df because the mean is estimated from the data. People write n and forget the n – 1.
  • Mixing sample size with categories. In chi-square, df comes from the table shape, not the total count. Use (rows – 1)(columns – 1), not the number of observations.
  • Rounding Welch’s df. Welch usually returns a decimal, and rounding it shifts your p value. Leave it as is.
  • Confusing groups and observations in ANOVA. df between uses the number of groups, df within uses total observations. Swapping them breaks the F test.
  • Ignoring the test’s assumptions. Using a pooled two-sample formula when the variances are clearly unequal gives you the wrong df. Pick Welch instead.

Frequently Asked Questions

How do you find degrees of freedom?

Start with your number of observations and subtract the number of quantities estimated from the same data. In short, df = total values minus restrictions. For a one-sample test that is n – 1.

How do you find degrees of freedom for a t test?

For a one-sample t test, df = n – 1. For a two-sample t test with equal variances, df = n₁ + n₂ – 2. For unequal variances, use the Welch equation, which the calculator computes for you.

How do you calculate df for chi square?

For a test of independence, df = (rows – 1) × (columns – 1). For goodness of fit, df = k – 1, where k is the number of categories.

What is df in statistics?

df stands for degrees of freedom, the count of values in a calculation that are free to vary after constraints are applied. It changes based on the test or model, which is why a calculator that picks the right formula is useful.

How many degrees of freedom do I have?

It depends on your test. Enter your numbers in the calculator above, choose the test type, and it returns the exact df with the formula and steps shown.

Try These Next

  • Kushagra Verma

    Researcher | BSc. CS + Financial Math

    Kushagra Verma is a researcher with a BSc in Computer Science and Financial Mathematics, focusing on data-driven analysis and real-world applications.

  • Yulduz Zaripova

    Data & Analytics Professional · MIT

    Yulduz Zaripova is a New York-based professional specializing in data analytics, financial engineering, and applied mathematics.