The Democrats will have 4765 delegates for their convention. 4051 are pledged delegates, that is those candidates won in the primaries and caucuses. For the most part, any candidate who has a certain level of support in a state, usually 15%, wins a proportion of the delegates based on their percentage of victory. For this reason, the percentage of a victory is often more important than who won the State.
In addition to pledged delegates, there are about 714 super delegates. These are party leaders, elected officials, and other establishment figure who can support whomever they like. Many super delegates announce their support of a candidate well in advance. But unlike pledged delegates, super delegates can change their support at any time up to the convention vote. A Democratic nominee needs 2383 delegates to have a majority to win the nomination. For more details exactly how delegates are allocated, check out this article.
Also, keep in mind that the number of delegates a State receives is not based on the State's population. The calculation is made based on the number of people who voted for the Democratic Presidential candidate over the prior three elections, with some additional changes made based on the number of electoral votes the State has had, and when the State holds its primary. States that hold a primary later in the season get bonus delegates.
As a result, different States with similar populations can have very different numbers of delegates. For example, Arizona and Massachusetts have about the same population size. But because Massachusetts has many more Democratic voters, it ends up with 116 delegates, while Arizona gets only 85. If Arizona moved its primary to later in the season, it could bump up its delegate count to 96.
Super delegates are given to States for each Democratic governor, Senator, or Member of Congress. But these super delegates are not pledged to any candidate and can vote for whomever they want. The elected officials are the super delegates. They cannot transfer this to anyone else. For more details, check out this article.
The Republicans also have RNC delegates which are party officials from the various States. But unlike the Democrats, these delegates are usually required to support the candidate who won their home States and there are only 168 of them. A candidate must collected 1237 delegates to have a majority at the convention. For more details exactly how delegates are allocated, check out this article.
Republicans allocate delegates very differently. Each State, regardless of size, gets ten delegates (five for each Senator) plus three delegates for each congressional district. These are given regardless of whether the elected officials are Republican or Democrat or how the State has voted in prior elections. States may, however, get bonus delegates for voting for the Republican nominee in the last election, having Republican Senators, having a majority Republican congressional delegation, or having majorities in the State Senate or House. There are no bonuses for holding later primaries, but States can suffer penalties for holding a primary before certain dates, or for holding a winner-take-all primary early in the season.
Bonus delegates can make a big difference for Republicans, especially in smaller States. For example, Delaware and South Dakota both have only one congressional district, meaning they both start with 13 delegates (five for each Senator and one for each Congressman). But SD voted for the Republican nominee, has a Republican governor, two Republican Senators, a Republican congressman and Republican majorities in State legislatures. As a result, it gets a total of 29 delegates, while Democratic Delaware is stuck with only its base of 13. For more details, check out this article.
Once a candidate of either party has a majority of delegates, or it becomes clear that it is virtually impossible for him or her not to reach that majority, the candidate can pretty much ignore the remaining primary states and begin focusing on the general election. This is why most States do not like holding late primaries. They tend to become irrelevant. But especially for Democrats, later dates mean more bonus delegates, so States must decide which is more important to them.
For candidates, winning with big percentages early is nice, but one's position (finishing first, second, or third) is more important because few delegates are at stake and finishing first or among the top means you get more notice (and likely more contributions) as you continue into the larger States. Once the race dwindles to two or three candidates, it becomes a fight over delegates. It is rare that either side would not have a clear nominee by the end of March (although 2008 for the Democrats was a big exception to this rule). Although there have been a few occasions when a candidate went into the convention without an outright majority, there has not been a fight that went past the first ballot since 1952, well before the modern primary system was put in place.