I'm facing some doubts in understanding how degrees of freedom are considered in distributions.
In particular let's refer to $t$ Student variable, that is
$$t=\frac{x-\bar{x}}{\hat{s}}=\frac{x-\bar{x}}{\sqrt{\frac{\sum(x_i-\bar{x})^2}{N-1}}}\tag{1}$$
Where $x$ is a gaussian variable, $\bar{x}$ is the mean value, $\hat{s}=\sqrt{\frac{\sum(x_i-\bar{x})^2}{N-1}}$ is the standard deviation taken from data.
Student probability density function is $$f(t)=C (1+\frac{t^2}{\nu})^{-\frac{\nu+1}{2}}\tag{2}$$
And on my textbook I find $\nu=N-1$ "because in $(1)$ appears the mean value $\bar{x}$, calculated from data, which implies the loss of a degree of freedom".
Question: Shouldn't it be $\nu=N-2$? In $(1)$ I have both $\hat{s}$ and $\bar{x}$ so there are two parameters determined from data.
On the other hand in the second form I wrote in $(1)$, $\hat{s}$ does not appear, so maybe only $\bar{x}$ should be considered as a constraint on data. But this does not make a lot of sense.
So in these cases where both the mean value and the standard deviation are determined from data, are the degrees of freedom lost 2 or only 1?
This is kind of a more general doubt: when more than one parameter is determined from data, but in some ways these parameters are related (as it is for $\bar{x}$ and $\hat{s}$), how many degrees of freedom are lost if all these parameter are considered?
Say for instance I determine $q$ parameters $p_1,p_2,...,p_q$ from the same set of data. All the parameters $p_2,...,p_q$ can be expressed as functions of data and $p_1$. Now I consider all the parameters together: how many degrees of freedom did I lose? $q$ or just $1$?