Idiosyncratic volatility is measured as the residual standrad error from a time-series regression of periodic excess stock returns on the returns of factor-mimicking portfolios.
Preliminary
Using the Fama/French three-factor model, you run the regression
$$r_{i,t} = \alpha_{i}+\beta_{MKT,i}MKT_{t}+\beta_{SMB,i}SMB_{t}+\beta_{HML,i}HML_{t}+\epsilon_{i,t}$$
where $r_{i,t}$ is the excess return of stock $i$ during period $t$, and $MKT_{t}$, $SMB_{t}$ and $HML_{t}$ are the period $t$ returns of the market, size, and book-to-market factors, respectively.
The residual standard error $RSE$ from the regression above is then calculated as
$$RSE_i = \sqrt{\frac{\sum_{j=1}^n{\epsilon_{i,j}^2}}{n-k}}$$
where $n$ is the number of data points that are used to fit the regression and $k$ is the number of parameters estimated by the regression.
Degree of Freedom
When the Fama/French three-factor model is used, there are four parameters estimated by the regression ($\alpha_i$, $\beta_{MKT,i}$, $\beta_{SMB,i}$ and $\beta_{HML,i}$), and thus in this case $k=4$. When the CAPM model is used, there are two parameters ($k=2$), and when the Fama/French/Carhart Model is used, there are five parameters ($k=5$).
Frequently, researchers will omit the subtraction of $k$ from the denominator of the calculation, or simply use $k=1$, which statistically assumes that the parameter estimates are exact, and therefore that $RSE$ represents an unbiased estimate of the standard deviation of the residuals.
Measure Idiosyncratic Volatility
Idiosyncratic volatility is then calculated by multiplying the residual standard error by $\sqrt{m}$ (with $m$ as the number of return periods in a year) so that it represents an annualized value. If the periodic excess returns used in the regression are represented in decimal form, the annualized residual standard error is frequently the multiplied by 100 so that idiosyncratic volatility ($IdioVol_i$) is measured in percent:
$$IdioVol_i = 100 \cdot RSE_i \cdot \sqrt{m}$$
Reference
Bali/Engle/Murray (2016), Empirical Asset Pricing: The cross-section of stock returns, Wiley.