To win a modern presidential election, a candidate needs to capture 270 of the 538 total electoral votes. States are allotted electoral votes based on the number of representatives they have in the House plus their two senators. Electors are apportioned according to the population of each state, but even the least populous states are constitutionally guaranteed a minimum of three electors (one representative and two senators).
This guaranteed minimum means that states with smaller populations end up having greater representation in the Electoral College per capita. Wyoming, for example, has one House representative for all of its roughly 570,000 residents. California, a much more populous state, has 53 representatives in the House, but each of those congressmen and women represent more than 700,000 Californians.
Since most states (48 plus Washington, D.C.) award all of their electoral votes to the person who wins the statewide popular vote, it’s mathematically possible to win more electoral votes while still losing the popular vote. For example, if one candidate wins by large percentages in a handful of very populous states, for example, they’ll probably win the popular vote. But if their opponent wins a bunch of smaller states by tight margins, he or she could still win the Electoral College. That’s basically what happened in 2016.
Take a look at all five times a president won the White House while losing the popular vote.