The Republican presidential race could end in the first contested convention in decades. It's a complex process, to say the least. Here's everything you need to know:

How would that work?
In most presidential elections, each party's national convention is a glorified infomercial to rubber-stamp the winning candidate. But in the rare case in which no candidate has won a majority of delegates, the convention becomes contested, and the nominee is chosen by the assembled delegates through a series of ballots. In the first round of voting, almost all of the delegates have to support the candidate they were chosen to represent based on the primary or caucus results in their state. In the second ballot, most delegates become "unbound," meaning they can vote as they please. If that round doesn't produce a majority winner, more delegates become unbound in the third ballot, and so on. With rival campaigns desperately trying to sway delegates, contested conventions become a chaotic mess of horse trading, backroom deals, and bitter infighting — and, sometimes, actual fistfights. After the riotous Democratic convention in 1924 (see below), the actor and humorist Will Rogers famously declared, "I do not belong to any organized party. I am a Democrat."

How rare are contested conventions?
Since the introduction of the modern primary system in the 1970s, it's only happened once. In 1976, President Gerald Ford arrived at the Republican convention only 24 delegates short of the nomination, with primary challenger Ronald Reagan needing 96. After some rancorous politicking, Ford won over enough uncommitted delegates to eke out a first-ballot victory. The last time a convention went beyond the first ballot was back in 1952, when Democrats needed three ballots to select Illinois Gov. Adlai Stevenson. But chances are high that it will happen at this year's GOP gathering in Cleveland in July. Republican Party leaders are actively trying to deny frontrunner Donald Trump a 1,237-delegate majority, fearing that his belligerent, racially charged nativism will turn off a majority of Americans and lead to a Democratic landslide. If the GOP does wind up with a contested convention, the 2,472 delegates could theoretically wind up nominating Trump; his nearest rival, Sen. Ted Cruz; or even someone who didn't run, such as U.S. House Speaker Paul Ryan.

How are the delegates chosen?
Only about a quarter are picked directly by the candidates. The remaining three-quarters — those in 44 of the 56 states and territories — are chosen by state conventions or committees consisting of local activists, volunteers, and elected officials. The presidential campaigns try to influence this selection process by lobbying for would-be delegates who support their candidate. These so-called "Supporters in Name Only," or SINOs, will then switch their vote the moment they become unbound. Thus far, Ted Cruz's staff has been much more proactive in lining up SINOs than the Trump campaign. "The Cruz campaign did its due diligence by forging these relationships in 2016 and before," says Josh Putnam, a political scientist at the University of Georgia. "The Trump folks are playing catch-up."

When can delegates switch their vote?
It varies widely from state to state. In all, about 95 percent of delegates are bound for the first ballot, less than half for the second vote, and even fewer for subsequent votes. The "unbound" delegates — the 5 percent who are not committed to a candidate on the first ballot — include all the representatives from North Dakota, as well as three Republican National Committee members from each state and territory.

Are these rules set in stone?
They're not. Each state and territory selects two of its delegates to sit on the Convention Rules Committee. Two weeks before the convention, this 112-person body sets the rules; any changes must then be approved by a majority of the delegates. Of particular interest this election cycle is Rule 40(B), which requires eligible candidates to have won a majority of delegates in eight states. That threshold was raised from five states in 2012, when the RNC sought to present a united front behind Mitt Romney. This cycle, only Trump and Cruz have won eight states. For Ohio Gov. John Kasich or any other would-be candidate to be considered, Rule 40(B) would have to be amended.

What other rules can change?
In theory, the Rules Committee can move the goalposts however they please. They could even free all delegates to vote for anyone they choose on the first ballot. But that "nuclear option" would all but guarantee a massive, potentially violent backlash from Trump's supporters, and would cause a deep and possibly irreparable schism in the party. "It's a classic example of changing the rules in the middle of the game," says Morton Blackwell, a veteran RNC member. "It would be widely and correctly viewed as an outrageous power grab."

The wildest convention
If the Republican race doesn't yield an outright winner, the party will be desperate to avoid a repeat of the 1924 Democratic convention — perhaps the most bitter and rancorous in history. That year, the Democrats were even more divided than the GOP is today: One frontrunner, William McAdoo, was supported by the Ku Klux Klan; the other, New York Gov. Al Smith, represented the party's anti-Klan wing. Held in sweltering heat at Madison Square Garden before the advent of air-conditioning, the convention was utter chaos. Nineteen candidates secured votes on the first ballot, and neither McAdoo nor Smith was able to consolidate enough delegates to win, so the process went on and on, amid fistfights and screaming matches on the convention floor. On Independence Day, the 10th day of the convention, 20,000 Klansmen gathered across the Hudson River to burn crosses. After a grueling 16 days and 103 ballots, a winner finally emerged: a little-known former congressman from West Virginia, John W. Davis, who went on to be crushed in the general election by incumbent President Calvin Coolidge. "There is something about a national convention that makes it as fascinating as a revival or a hanging," said writer H.L. Mencken, who covered the chaos. "It is vulgar, it is ugly, it is stupid...and yet it is somehow charming."