How is the number of electoral votes per state determined?

As far as I know, a state gets as many electoral votes as it has districts, and how many districts it has is determined by population. For example, Kansas isn't a small state, but the population is very spread out (Because they're all farmers) so they have districts that are large in area but still have the same population as all other districts. Rhode Island only has one district, because it is very small and not very populated. New York City may be at least a district or two just by itself, because the population there is so high