To elaborate on bfv's point:
There are 538 electoral votes. They are proportioned to the states according to their number of senators (2 per state) and representatives (varies by population; adjusted after every 10-year census). Each electoral vote is decided by the winner of the popular vote in the elector's district. In most states, it is winner take all; if a state has five electoral votes and the republicans only win one district, all five electoral votes go to the democrats. I believe New Hampshire and one other state allot their electoral votes proportionally.
This is how George W Bush lost the popular vote by 2 million votes but won the electoral college; he won the recount in Florida by 238 votes, thereby swinging all 29 of Florida's votes to Bush.