Both major political parties of the U.S.—the Democratic Party and the Republican Party—officially nominate their candidate for President at their respective national conventions. Each of these conventions is attended by a number of delegates selected in accordance with the given party's bylaws.
Both parties operate with two types of delegates: pledged and unpledged. The group of unpledged delegates, also known as superdelegates, generally comprising current and former elected officeholders and party leaders, are free to vote for any candidate they wish at the convention. The group of pledged delegates, comprising delegates representing the party committee of each state, are expected to vote in accordance with the rules of their state party.
Depending on state law and state party rules, when voters cast ballots for a candidate in a presidential caucus or primary, they may be voting to actually award delegates bound to vote for a particular candidate at the state or national convention, or they may simply be expressing an opinion that the state party is not bound to follow in selecting delegates to the national convention.
In recent elections, the eventual nominees were known well before the actual conventions took place. The last time a major party's nominee was not clear before the convention was in 1976, when incumbent president Gerald Ford narrowly defeated Ronald Reagan.