(CNN) The Democratic primary is not a race to win states, but to amass delegates. It's delegates who pick the nominee at the Democratic National Convention, scheduled for July in Milwaukee.

Read below to understand how they're selected and what happens to the delegates won by candidates who drop out of the race.

This will get complicated. You have been warned.

The most important thing to remember is the magic number: 1,991.

That's the number of pledged delegates required to cinch the nomination. It's more than half the total of 3,979 pledged delegates.

Two more key things:

15% threshold -- A candidate can get delegates only if they get to 15% of the vote at EITHER the state level OR in a particular congressional or state legislative district.

Proportionality -- Democrats allocate their delegates proportionally. That means a candidate could not get the most votes in any particular state but still amass a solid base of delegates if he or she is achieving the 15% thresholds.

One good way to look at this is that it is 57 contests in the states, territories and the Democrats Abroad organization, but also hundreds of district-level contests. Candidates can get delegates either way.

The information below is specifically about Democrats. Republicans treat the system somewhat differently, but President Donald Trump has it sewn up this year.

3,979 pledged delegates

What is a pledged delegate? A pledged delegate is a delegate allocated to a candidate based on his or her performance in a caucus or primary. The campaigns have the ability to vet these delegates and can even submit a list of names to represent them.

Simple enough, right? Wrong!

2,591 district-level pledged delegates -- Not all pledged delegates are selected in the same way. There are state-level delegates and district-level delegates. Most district-level delegates are determined at either a congressional district or state legislative district level.

1,388 state-level pledged delegates -- The rest of the pledged delegates, 1,388 of them, are awarded at the state level. And there are two kinds of state-level delegates:

- "Pledged Party Leader and Elected Officials (PLEO)" delegates. These are high-ranking elected officials, like big-city mayors, who get to be delegates at the convention. They're pledged proportionally to the top performers in their states.

How to get delegates without winning anything -- It is possible for a candidate to get less than 15% in the statewide contest but still obtain delegates by getting better than 15% at the district level. That's how Klobuchar emerged from Iowa with a delegate. She did very well in the 4th Congressional District, but got less than the 15% threshold statewide.

If one candidate is ahead, as Biden was in South Carolina, there's a good chance he or she will get a good portion of the delegates from that state. But Sanders still got 15 delegates there.

771 unpledged delegates

If you're old enough to remember 2008 or 2016, you might remember superdelegates. Also known as unpledged delegates or "automatic" delegates, these are the party bigs -- congresspeople, governors, senators and former presidents -- who aren't tied to any particular candidates regardless of what happens in their state primaries.

In 2020, superdelegates/unpledged/automatic delegates won't get a say on the nominee at the convention unless or until a first ballot fails to get a nominee. There is one exception: If a candidate gets enough delegates to make it mathematically impossible for superdelegates to change the outcome, then they can vote. That means they could be decisive if there is no consensus nominee by the convention.

Note: The number of unpledged delegates can change. If a member of Congress dies or resigns, for instance, their delegate spot goes with them until a replacement is put in office. The number of pledged delegates, however, stays the same.

The after-primary: What happens to the delegates of former campaigns?

After the voting, the coming together. The last primary contest will be in June, but about 90% of the country will have had a say by the end of April. Assuming there is no one with a clear majority, that will leave some three months for campaigns to reach out to delegates pledged to former candidates as well as to unpledged delegates who had supported former candidates in order to solicit support on the convention floor.

What happens to delegates pledged to dropouts? District-level delegates pledged to former candidates will become very popular if the fight between Biden and Sanders goes all the way to the convention. There's nothing that legally requires them to vote for anyone in particular, although different state parties have different rules. The national party says they should follow their conscience. Most state-level pledged delegates have not been selected yet, so they will be reallocated among remaining candidates once they are finally selected.

Best case. Most Democrats agree that the best scenario would be for all but the winning candidate to suspend their campaigns before the convention. The system is built assuming the party comes together. This year, however, that seems less likely than in years past.

Worst case. These things usually work out before there is voting on the convention floor. The last time the first round of voting didn't anoint a Democratic nominee was 1952 (that was Adlai Stevenson, and Democrats lost in November of that year, to Dwight Eisenhower).

After really difficult primaries, Democrats usually lose.

Hubert Humphrey lost in November after there was violence outside the controversial 1968 convention , when party elders selected him over the anti-war favorite George McGovern. Four years later, McGovern got the nomination. He lost the election.

In 1980, Sen. Ted Kennedy took his campaign to the convention before conceding. (President Jimmy Carter lost in November.)

In 1992, a bruising Democratic primary was offset by a bruising Republican primary for President George H.W. Bush. And Bill Clinton was helped in the general election by Ross Perot's bid as an independent.

Also: It's relatively rare for a Democratic nominee to get a majority just with pledged delegates. The last one to do it was John Kerry in 2004, even after a tough primary. (He lost in November.)

The aforementioned 2008 contest between Barack Obama and Hillary Clinton is the only one of these that ended in a victory in the general election.

This year, Sanders has said his fight is with the Democratic establishment. And the Democratic establishment now seems to be circling the wagons around Biden.

So get ready.