How many degrees of freedom do you use in ANOVA calculations?

If you have n data points, and two categorical/discrete variables with k_1 and k_2 levels, how many degrees of freedom would you use in the corresponding F-test?

Different stat packages (Stata and SPSS) seem to be using different values, and I was wondering if there was a theoretically correct answer. Thanks!