The degrees of freedom (df) in a contingency table represent the number of values that can be arbitrarily changed without altering the marginal totals. For a contingency table with R rows and C columns, the calculation is straightforward.
In a contingency table, the constraints come from the fixed row sums and column sums. If you know the row totals and column totals, you can freely choose the frequencies for most cells. Once these are chosen, the remaining cell frequencies are determined.
The formula to calculate the degrees of freedom for an R x C contingency table is:
$df = (R - 1)(C - 1)$
Where:
Each row contributes $(R - 1)$ degrees of freedom because one value in the row is determined by the total. Similarly, each column contributes $(C - 1)$ degrees of freedom.
Therefore, when the number of frequencies are put in a cell in a contingency table, the degree of freedom will be (R - 1) (C - 1).