"During the general election your vote helps determine your State’s electors. When you vote for a Presidential candidate, you aren’t actually voting for President. You are telling your State which candidate you want your State to vote for at the meeting of electors. The States use these general election results (also known as the popular vote) to appoint their electors. The winning candidate’s State political party selects the individuals who will be electors." [Federal Register, National Archives]
"Every State is allocated a number of votes equal to the number of Senators and Representatives in its U.S. Congressional delegation—two votes for its Senators in the U.S. Senate plus a number of votes equal to the number of its Congressional districts." [Distribution of Electoral votes, National Archives]
In some states, the majority of voters will almost always vote Republican. In other states, the majority of voters will almost always vote Democrat. There are a handful of states where the outcome is less certain. Because these electoral votes could be won by either party, the so-called "swing states" or "battleground states" have an outsize role in electing the president. "Swing states" can change over time, but in recent contests, these are Michigan, Georgia, Arizona, Pennsylvania, Wisconsin and Nevada.