Why do you use n-1 in Standard error of the mean but n in hypothesis testing When you divide in hypothesis testing you use the formula:
$$
\frac{\bar X-\mu}{s/\sqrt n}
$$
but the standard error of the mean is:
$$
\frac s{\sqrt {n-1}}
$$
Why don't you use $n-1$ when calculating the standard error using the sample population?
 A: The $n-1$ term DOES NOT appear in the formula for standard error as you have written it. The $n-1$ term does appear, however, in the equations for the sample variance and the sample standard deviation. It is used to correct for the fact that $ \hat{\sigma^2} = \frac{1}{n} \sum(x_i - \bar{x})^2 $ is a biased estimator of the variance. This can be shown as follows:
$ \hat{\sigma^2} = \frac{1}{n} \sum(x_i - \bar{x})^2 = \frac{1}{n} \sum (x_i^2 - 2x_i\bar{x} + \bar{x}^2) = \frac{1}{n} \sum (x_i^2 - x_i\bar{x} - x_i\bar{x} + \bar{x}^2) $ 
$ = \frac{1}{n} \sum (x_i[x_i-\bar{x}] - \bar{x}[\bar{x}-x_i]) =  \frac{1}{n} \sum (x_i[x_i - \bar{x}]) - \frac{\bar{x}}{n} \sum [\bar{x} - x_i] $
Since $ \frac{\sum [\bar{x} - x_i]}{n} = 0 $, we get:
$ = \frac{1}{n} \sum (x_i[x_i - \bar{x}]) = \frac{1}{n} \sum ({x_i}^2 - {x_i}\bar{x}) =  \frac{\sum {x_i}^2}{n} - \bar{x} \sum \frac{x_i}{n} = \frac{\sum {x_i}^2}{n} - \bar{x}^2 $
This means that:
$ E[\hat{\sigma^2}] = E[X^2] - E[\bar{x}^2] $
We know that:
1) $ \sigma^2 = E[X^2] - (E[X])^2  \rightarrow E[X^2] = \sigma^2 + (E[X])^2 $
2) $ \bar{\sigma}^2 = \frac{\sigma^2}{n} = E[\bar{x}^2] - (E[\bar{x}])^2 \rightarrow \frac{\sigma^2}{n} + (E[\bar{x}])^2 $
Now substitute these equations back into the above equation to get:
$ E[\hat{\sigma^2}] = \sigma^2 + (E[X])^2 - (\frac{\sigma^2}{n} + (E[\bar{x}])^2) = \sigma^2 - \frac{\sigma^2}{n} = \sigma^2 (\frac{n-1}{n}) $
To get an unbiased estimator for $ \sigma^2 $, we multiply $ \hat{\sigma^2} $ by $ \frac{n}{n-1} $ to get: 
$ s^2 = \frac{n}{n-1} \times \frac{1}{n} \sum(x_i - \bar{x})^2 =  \frac{1}{n-1} \sum(x_i - \bar{x})^2 $
The quantity $ s^2 $ is known as the sample variance, and $ s $ is the sample standard deviation. The standard error is simply $ \frac{s}{\sqrt{n}} $.
A: The standard error of the sample mean actually is 
$$
\frac s{\sqrt n}
$$
(there is no $n-1$ term here).
In hypothesis testing and confidence intervals you use $Z=(\bar X-\mu)/(\sigma/\sqrt n)$ because you are using the Central Limit Thorem that states that the sample mean $\bar X$ has a normal distribution with standard deviation $\sigma/\sqrt n$. If you use the sample standard deviation this is repaced by $s/\sqrt n$ and the normal is replaced by a Student distribution.
Now, the $n-1$ comes into play when computing
$$
s=\sqrt{\frac{1}{n-1}\sum (x_i-\bar x)^2},
$$
and it is there to account for the fact that, when computing $s$, you use the sample mean $\bar x$ in place of the (real, unknown) mean $\mu$.
A: In this answer, it is shown that since the sample data is closer to the sample mean, $\overline{x}$, than to the distribution mean, $\mu$, the variance of the sample data, computed with
$$
\frac1n\sum_{k=1}^n\left(x_k-\overline{x}\right)^2
$$
is, on average, smaller than the distribution variance. In fact, on average,
$$
\frac{\text{variance of the sample data}}{\text{variance of the distribution}}=\frac{n-1}{n}
$$
This is why we use
$$
\frac1{n-1}\sum_{k=1}^n\left(x_k-\overline{x}\right)^2
$$
to estimate the distribution variance given the sample data.
A: Previous respondents have focused on when, how and why Bessel's correction is used to obtain an unbiased estimate of the standard deviation and clarified that it is not used for calculating the standard error of the mean. However, they have not, so far as I can see answered the very good question posed: "Why don't you use n−1 when calculating the standard error using the sample population?"
A few words suffice on this topic. It has already been explained admirably well in the previous response, due to robjohn, that Bessel's correction is applied in the estimation of a distribution's standard deviation because deviations from the sample mean are generally smaller than deviations from the mean of the hypothetical distribution generating the data. (The sample mean follows the crowd of sampled values, if you will, whereas the distribution mean remains where it is.) However, when we actually know the distribution's mean and use deviations from it, instead of from the sample mean, to estimate the standard deviation, Bessel's correction should not be applied, because the aforementioned biasing effect does not occur.
One can derive the standard error of the mean by proceeding from appropriate definitions. One would then find that the standard error, if it is not nothing at all, is the expected deviation of the sample mean from the distribution's mean. Consequently, we obtain an expression for the standard error in terms of (n and) that form of the standard deviation which uses deviations of sampled values from the population mean or mean of the hypothetical distribution, not from the sample mean. Consequently, it is not and cannot (ever) be appropriate to apply Bessel's correction in this part of the process. This is why an n-1 expression does not appear in any formula for the standard error in terms of σ and n.
It may well be that we are in a position of having to estimate the distribution's standard deviation in order to obtain the standard error on the sample mean. In that case, we will of course use the appropriate sample statistic with the Bessel's correction applied, to get our estimate of σ. So in the end we do apply the correction for precisely the same reason, that we need to estimate what the distribution's standard deviation is. But it does not feature otherwise, because the standard error is by definition an expected deviation from the distribution's mean rather than the sample mean.
That came out less succinctly than I had anticipated, but I hope the main point is apparent in the end and that this satisfies the curiosity of those who find their way to this query.
