Why does some candidate win popular vote yet loses on election?

Why is it possible for a candidate to win on popular vote, yet lose on election?
Doesn't most states do winner take all system, meaning if you win popular vote it automatically means you win the states electoral votes? Meaning you'll win?
6 answers 6