Some minor inaccuracies in the below:
The nationwide election is not to elect a president but to determine each state's representation in the Electoral College. Each state's representation in the College is the number of members of the House of Representatives (Congressmen) that state returns (which is dependent of the state's population) plus its two Senators. The larger states, such as California and New York, tend to have proportionally fewer Congressmen than small states. All Electoral College members vote for the candidate who "won" their state.
The senators are not in the Electoral College. The electoral college consists of delegates. Each state gets a delegate for each member of the House of Representatives and a delegate for each senator of which there are always two per state. The number of representatives (i.e. members of the House of Representatives) are roughly in proportion to the population of the state based on the ten yearly census.
The imbalance arises because all states - even really small ones - are entitled to at least one representative and exactly two senators.
Most states instruct all of the electoral college delegates to vote for the presidential candidate that won the popular vote in their state. So, for example, in California, the Democrat candidate almost always wins the popular vote and therefore all 55 electoral college delegates are instructed to vote for the Democrat. However, Maine and Nebraska instruct two delegates to vote based on the winner of the popular vote and the other delegates to vote based on the split of representatives. So Maine has 11 delegates, two of them will vote based on the popular vote over the whole state and the other nine will vote based on the representatives returned. If the Dems win four districts and the GOP wins five and the popular vote goes too the GOP, then seven Maine delegates will vote Republican and four will vote Dem.