The number of degrees of freedom depends on how many parameters you’ve estimated.
In a multiple regression, for example, in which you have n data points and k independent variables and you’re estimating k slope coefficients and one intercept, dof = n − k − 1.
What are types of problems in which you’re seeing dof = n − 2?