It's clear why you use n for the whole population, the problem is why (n-1). The answer for this is simply that if you use (n) the statistical estimator is biased, and the right correction to make it unbiased happens to be (n-1). That's called Bessel's correction.
I linked some sites that go into the derivation of why using n is biased in more detail.
Description of Chris Rackauskas was very good. As a simple example, I could also explained as follows. In the sample, when we calculate the standard deviation, then there is one observation value which is not free. This situation will be obvious when sample sizes are small. For example if we have a value of observation is 1, 2, and 3. the mean is 2, so the value of observation 2 is not free of mean = 2. Deviation from 1 to 2 and 2 to 3 on average is 1, a value that is equal to sample standard deviation (when divided by n-1). If divided by n, its value will be biased, i.e, greater than 1. In a population, theoretically, is very large, so it will not be found such bias when calculating the standard deviation of the sample.
When we calculate the mean for say "n" numbers, naturally the mean will lie in between smallest and largest of the "n" numbers. When one calculates the standard deviation, the person subtracts the mean from the quantity, since, mean lies in between the numbers whose mean has been calculated, that's why there is a chance that one deviation will be zero. In order to remove this zero deviation, one subtracts this from the number of observations. That's why instead n, n-1 is used.