The number of senators each state has and the number of representatives each state has determine the amount of electoral votes each state is granted. Each state has two senators. The number of representatives each state has depends on its population. The 23rd Amendment of the Constitution gave Washington D.C. three electoral votes even though the city is not a state.
The presidential candidate who gets the most electoral votes wins the presidency. There have been three separate occasions when the candidate who had the most votes did not win. Additionally, this set up allows the U.S. speaker of the House, by vote of the House of Representatives, to choose the president and vice-president if the electoral vote ends in a tie. Each member of the House gets one vote. Thomas Jefferson won the presidency in this manner.
The original intention of the Founding Fathers was that a separate group of people are to make up the electoral college, and they are to cast their votes for a president. As of 2014, the electors are required to vote for the candidate who won the popular vote in their state. However, Maine and Nebraska do not give all their votes to the candidate who wins the popular vote.