How did 5 of our 45 Presidents come into office without getting the most popular votes nationwide?

They did this by winning a couple of states by very small margins -- thus getting all of the electoral votes from those states -- while losing the rest of the country by a large margin.

In 2016, Donald Trump became President even though Hillary Clinton won the national popular vote by over 2,800,000 votes. Trump won because he carried Michigan by about 11,000 votes, Wisconsin by about 23,000 votes, and Pennsylvania by about 44,000 votes. Each of these 78,000 votes was 36 times more important than the 2,868,518 votes cast in other states.

In 2000, George W. Bush became President even though Al Gore won the national popular vote by 537,179 votes. Bush won because he carried Florida by 537 votes. Each of these 537 votes was 1,000 times more important than the 537,179 votes cast in other states.
The 1876 election was similar to the 2016 election in that small margins in three states enabled Rutherford B. Hayes to eke out a one-vote win in the Electoral College. Hayes led Samuel Tilden by 889 votes in South Carolina, 922 votes in Florida, and 4,807 votes in Louisiana -- a total lead of just 6,618 votes. Each of those 6,618 votes was 38 times more important than Tilden's nationwide lead of 254,694.
Similarly, in 1888, Benjamin Harrison became President by carrying New York by a small margin -- even though Grover Cleveland won the national popular vote.

In 1824, John Quincy Adams became President even though Andrew Jackson received the most popular votes nationwide and even the most electoral votes. Because Jackson did not receive an absolute majority of the electoral votes required by the Constitution, the presidential election was thrown into the U.S. House of Representatives. Under this special procedure, each state had one vote, and John Quincy Adams emerged as President. more info
SUPPORT NATIONAL POPULAR VOTE
The National Popular Vote bill would guarantee the Presidency to the candidate receiving the most popular votes in all 50 states and D.C. New 8-minute video

This is a great time to send your state legislators an email asking them to support the National Popular Vote bill. Most of them are up for election on November 3.