A trader gambling on the outcome of the 2016 elections consults the PredictIt website, part of the legal “predictions market” that academic researchers use to gauge the electoral cycle. (Michael S. Williamson/The Washington Post)

It was another primary-night Tuesday at a K Street bar, and the booths were filled with nerds who couldn’t stop talking politics. So goes every night in Washington, but something was different here. The shadowy basement of PJ Clarke’s was brightened by screens — phones, iPads and laptops — in the hands of beer-sippers in rumpled button-downs. They were talking Trump and Cruz, approval ratings and Supreme Court picks — and how it all added up to sweet, sweet money.

Thousands of dollars were being gambled on the outcomes. And it was all completely legal.

Political gambling has long been banned in the United States, but the government makes an exception for “prediction markets” such as PredictIt, host of this bar gathering, because of the valuable data they produce for academic researchers. It turns out that treating the great electoral horse race like a day at Churchill Downs provides a pretty good sense of how real voters will decide.

But only if the gamblers can place their bets without letting their own political hopes and dreams color their choices. In this unfathomable election, that can be difficult.

“Utah is pretty steady at 90 cents for Cruz,” Matt Baker, a 27-year-old research analyst, announced to his table. “Trump’s at 92 cents in Arizona right now!”

“All right, all right,” conceded his friend Scott Wetzel, a 33-year-old policy analyst. “I will buy some Trump.”

So Wetzel, who happens to support Hillary Clinton for the presidency, pulled out his credit card and bet that Trump would win the Republican contest in Arizona. If it’s going to happen, he might as well profit.

“On principle,” he added, “I will not spend more than $10.”

Arthur Karell consults his phone, laptop and TV news to monitor his wagers at PredictIt’s watch party at PJ Clarke’s as the results of primary votes come in March 22. (Michael S. Williamson/The Washington Post)

Although PredictIt’s 29,000 active traders had an average of $121.36 in the game last week, Baker had $1,400. Others are playing thousands of dollars at a time.

PredictIt breaks the election cycle down into a near-endless list of yes-or-no questions: “Will Bernie Sanders win Hawaii?,” “Will Ted Cruz win the Republican nomination?,” and even far-fetched scenarios such as “Will Paul Ryan win the 2016 presidential race?”

Traders can buy “yes” or “no” shares on each question. As with the stock market, the price for shares is determined by the supply and demand as traders buy and sell them. As of Wednesday afternoon, the hive mind of PredictIt traders seems to think that Ted Cruz has a 79 percent chance of winning next week’s Wisconsin primary: “Yes” shares wagering on his victory were going for 79 cents — a spike upward from 59 cents the previous night — which means that a “no” share wagering on his loss would cost 21 cents. The winner takes home $1.

It may seem troubling to see the fate of the nation treated like a cheap round of poker, but the gamification of politics is actually in­cred­ibly useful to economists and political scientists.

“Prediction markets help us understand all sorts of things about the dynamics of campaigns and the impact different events have,” said David Rothschild, an economist at Microsoft Research and the founder of prediction aggregator PredictWise.com . “We can start to figure out how much that debate gaffe really cost somebody, or, how effective was that ad?”

Researchers across the world depend on the data from PredictIt and the Iowa Electronic Market (IEM), a smaller futures market that opened in 1988. Both are backed by academic institutions: IEM through the University of Iowa, PredictIt through New Zealand’s Victoria University at Wellington. The D.C.-based campaign technology and background-checking firm Aristotle International runs the PredictIt platform.

Only PredictIt and IEM have been granted permission by the U.S. Commodity Futures Trading Commission to run these kinds of markets. The CFTC sets guidelines — such as an $850 limit — to keep them from growing to the size of popular European betting behemoths like BetFair and Paddy Power.

PredictIt bettors on primary night. “Everyone likes to bet on their own favorite long shot,” but that’s not always in their best interest, explained one player. (Michael S. Williamson/The Washington Post)

Still, there are thousands of dollars to be won for those with a knack for the game.

“In the Republican primary, you had, like, 24 different Republicans who are running. So hypothetically, if you buy a ‘no’ share of everyone in the Republican primary, guaranteed worst-case scenario, you’re going to get $23,” Michael Burleson, a 28-year old tech consultant explained to a group of traders he met at the bar. “So I just went in and bought tons of ‘no’ shares across the board. All I had to do is wait for the caucuses, and I’m good to go.”

“Because everyone likes to bet on their own favorite long shot,” chimed in Rob Fox, a software developer.

They all would have done well to bet “yes” on Donald Trump last summer. Back then, the shares wagering that he would win the GOP nomination were going for a mere 12 cents. On Wednesday, they were at 61 cents (but falling again, after hitting 80 cents a month ago).

Letting your own views steer your wagers is where it all goes wrong, Fox warned. He knew. He had wanted Joe Biden to run for president so badly.

“I thought I made too much sense,” he said. “Labor Day, when he was running [in a parade] in Delaware — look, he’s telling us that he’s running!”

Fox lost hundreds of dollars on Biden. But he kept playing. It’s so addicting, traders said, that some think PredictIt is actually making its gamers — mostly people in their 20s and early 30s — more actively engaged in politics.

They sneak peeks at the site during their workdays and check how their shares are doing on their phones at dinner. They’re constantly assessing the latest polls, reading up on candidate strategies and watching for gaffes that could move share prices.

That’s why prediction markets do such a good job at anticipating election outcomes. Polls ask a limited number of voters whom they would vote for today. Prediction markets ask thousands of very informed people to make their best guess at what will actually happen — and to be so confident that they would put their own money on it.

That was the problem for Greg Brooks, who sat at the end of the bar as the evening wound down. He had money in PredictIt, but he quit betting when he got hired onto a presidential campaign.

Which one?

“One of those that is over now,” he said.

Hey, at least he was free to invest again. There’s a nearly 40-cent per-share profit to be made on Trump winning the nomination — should Brooks bet that way, and should history unfold that way.

But Brooks thought he’d wait to see whether there’s a contested convention, he said. He’s just not ready to bet on numbers alone.

This story was updated on March 30 to reflect the latest PredictIt numbers.