How do I work out degrees of freedom for terms in an ANOVA?
For N subjects and g group variables (factors) with respective levels L1, L2, ... , Lg and a within subjects factors, W, the table below gives the degrees of freedom for various types of sources variation in an analysis of variance.
Source of variation 
df 

Factor 
L11 

2way interaction 
(L11)(L21) 

Kway interaction of factors 
$$\prod_text{k} (L_text{k}1)$$ 

Between subjects error terms 


Error (oneway anova between subjects) 
N  L1 

Error (between subjects) 
N  df of terms involving between subjects factors  1 

Within subjects error terms 


Error (subjects x W1), no between subjects factor 
(N1)(L11) 

Error (subjects x W1 x W2, no between subjects factor ) 
(N1)(L11)(L21) 

Error (subjects x W1 x W2, 1 between subjects factor) 
(NL1)(L21)(L31) 

Error (subjects x Within subjects interaction) 
df of Error (between subjects) x df(Within subjects interaction term) 
Reference
Boniface DR (1995) Experiment design and statistical methods for behavioural and social research. Chapman and Hall:London. (This book contains further details about computing degrees of freedom and also SS in balanced designs for terms in an ANOVA).