@Phillip's answer is correct, but there's a bit more to add...
In the US, there really isn't any "national election" except for the "meeting" of the electors in early- to mid-December.
There are 51 distinct per-state elections for President and Vice President (one for each of the 50 states and one for the District of Columbia). Like all other elections in the US, these are run using state-specific rules (although elections for Members of Congress, Senators, the Vice-President and the President, the state-specific rules need to follow the rules laid out in the constitution (for example, the President and VP candidates must be at least 35 years old and "natural born citizens")).
Each of the state presidential elections elects a group of "electors". The number of electors in each state is set by the number of Members of Congress (varies by population) and the number of Senators (always 2) from the state.
Most states have a rule that the full slate of electors associated with the candidate who receives the largest popular vote in that state are "elected" (Maine and Nebraska have different rules). This whole "elector" thing is mostly hidden from voters. Voters don't see any elector information on the ballot; they see the presidential/vice-presidential combinations and they vote for one of them.
The main election is in early November. A little more than a month later, the winning group of per-state electors meet in each state capital and vote for a president and a vice-president. In most states (I think), there's no obligation for the elector to actually vote for the candidate he/she represents - and this past election had a large number of so-called "faithless electors".
Those per-state vote counts are sent to Washington (actually, the signed ballots are sent). They are counted up, and if there is a majority vote for president, that person is president (same rule for VP). If there isn't a majority, well, look it up, it gets complicated.
So, the process is:
In each state:
Phase I:
- The state has a process for parties to be recognized (this may include a process for individuals to get "on the ballot" without party affiliation (usually via petition))
- The state parties have a process for deciding who the "winner" is from the state (following state rules). This usually involves primaries or caucuses (or both)
- The parties have a national nominating convention where the winners from each state run against each other to become the party's national candidate. In these conventions delegates from each state vote for the winner. The number of delegates from a state is loosely proportional to the population of the state (California gets many more delegates than Wyoming, but it's not strictly proportional, and the rules are set by each party).
- The winner of the party national convention becomes the party "nominee" in all states where that party is on the ballot.
- The party's nominee submits a list of elector candidates to each state's election officials. At the end of the November election, the state's electors are drawn from the winner's list (in Nebraska and Maine, it's more complicated)
At this point, we now have the ballot set in each state. One state may have only 2 candidates (a Republican and a Democrat), another state may have many more.
Phase II:
- In November, the 51 presidential elections happen - everyone sees this as a "national election"
- Once the results from each state's presidential election are established, the electors from that state are fixed
- About a month later, each state's electors meet and "vote"
- The tallies from each state's elector vote are combined and, if there are majorities, a winner is declared
If there's no majority, count on all hell breaking loose, and everyone reading up on Article II and the 12th amendment of the constitution.
So, yes, there are roughly two phases, but it's very complicated.