Friday night’s military coup against Turkey’s civilian leadership appears to have failed. By Saturday morning, the New York Times reports, Turkey’s security services had detained "thousands of military personnel" who had participated in the coup.

"There were few signs that those who had taken part in the coup attempt were still able to challenge the government, and many declared the uprising a failure," the Times’s Tim Arango and Ceylan Yeginsu write.

That raises two big questions this morning: Why did Turkey’s coup fail, and what happens in the country next?

Naunihal Singh has some helpful answers. He is an academic and the author of Seizing Power, a groundbreaking book on coups. Singh drew on a huge data set of coup attempts, as well as hundreds of hours of interviews with actual coup participants, to develop a comprehensive picture of what makes coups succeed or fail.

Last night, as it seemed the coup in Turkey was faltering, I called up Singh to ask him what he thought of the situation — and what it tells us about the future of Turkish democracy.

According to Singh, the failure of Turkey’s coup likely wasn’t determined by the coup plotters’ military strength, or even their support inside the military. It was determined by their inability to make it seem like they were going to succeed. The ability to shape perceptions of success, often through media, is crucial in coups — basically, if people think a coup is going to succeed, they usually just join up because they don’t want to be on the wrong side of the guns.

The Turkey plotters failed to create this perception, and now they — and Turkish democracy — may end up paying the price.

Turkey fits the historic pattern of failed coups

The first thing to understand about Turkey’s coup, according to Singh, is that the coup plotters didn’t put up scorched-earth military resistance. Turkish Prime Minister Binali Yildirim says that 265 people were killed in clashes — which is horrible (if true) but still not nearly the number there could have been had the tanks and troops throughout Istanbul and Ankara engaged in full-scale conflict.

"Coup supporters didn’t try to fight till their last breath," Singh says. "These are groups that are willing to surrender even if they might be tried for treason afterward."

According to Singh, this is common in coups. The whole point of a coup is for a faction of the military to take over the government without kicking off a civil war. They want control over a stable society, not one fracturing into bloodshed. That means that coups are typically marked by defections to whatever side appears to be winning, rather than outright military conflict between factions.

In coups, then, perception is reality: If Turkey’s coup leaders had successfully created the perception that the overthrow of President Recep Tayyip Erdogan was inevitable, then even Erdogan sympathizers in Turkey’s security services would have been unlikely to oppose them.

"When a coup starts, it’s by faction: It’s a small number of people who are trying to takeover, and perhaps a small number of die-hard loyalists, but most of the military is sitting in the middle," Singh explains. These fence sitters "choose the side that they think will win, and when enough people do that it has a self-fulfilling aspect."

Turkey’s coup plotters, by all accounts, failed to do that.

One critical way to create this self-fulfilling prophecy, according to Singh’s research, is to take control of the broadcast media. Once you’ve got the radio and television stations, you then use them to tell everyone the government has already been overthrown. That convinces people in the military that the coup has succeeded, leading them to take your side.

But reports on the ground say that this didn’t happen. President Erdogan managed to make a televised statement opposing the coup (though he did so, amusingly, via a cellphone on Skype). Leaders of major political parties, including the opposition, publicly opposed the coup.

Perhaps most importantly, the coup plotters did a very poor job of getting their message out. While they did seize a number of media outlets, like CNN Turk, they failed to use them effectively in broadcasting their message.

"We had no clear statement from the coup forces. No leader came on TV, no real manifesto," Zeynep Tufekci, a professor at the University of North Carolina who was in Turkey during the coup attempt, tweeted. "In Turkey, successful coup attempts are massive, happen within chain-of-command, and take over media immediately."

The coup plotters failed to establish the perception that they were fully in control, and hence failed to win the overwhelming bulk of the military to their side. It’s still early, so we can’t be sure of anything. But given Singh’s research, and the information we have, it’s very likely that this explains — at least in part — why they failed.

What happens when coups fail

After any coup fails, the nightmare scenario is a mass, violent purge of "disloyal forces" by the government. Erdogan’s heated rhetoric last night suggested this was a real possibility. He blamed the coup on his political opponents in the Gülen Movement, and warned in a televised address that "they will pay a heavy price for their treason to Turkey."

Luckily, Singh says, violent purges after coups are actually fairly rare — because they’re not in the government’s interest.

When the government starts killing people in the military, even officers who weren’t involved in the current coup get nervous about the government one day killing them. That makes another coup in response to the purges — Singh calls this a "counter-coup" — more likely. Governments know this, and so generally respond to coups by putting loyalists in charge of the military, rather than killing soldiers en masse.

"What you [typically] see is more consolidation than retribution," Singh says. "Consolidation [means] making sure your guys are in power. But you don’t see retribution because too much retribution sets up the risk of a counter-coup."

This doesn’t mean mass violence is outside the realm of possibility. But it does mean that Erdogan’s heated rhetoric isn’t necessarily a good guide to what he’ll actually do when it comes down to it.

The more subtle and pernicious consequence could be serious damage to Turkey’s democracy — and even a transition to authoritarianism.

For years now, Erdogan has been attempting to stifle dissent and consolidate power in his own office. He’s cracked down on Turkey’s freedom of the press, violently dispersed anti-government demonstrations, and pushed constitutional changes that would consolidate dangerous amounts of power in the office of the presidency.

Previously, Turkish democratic institutions had seemed strong enough to fend off Erdogan. Erdogan’s party lost a June 2015 national election, in large part due to the Turkish public rejecting Erdogan’s proposal to amend the constitution and give himself greater powers.

But it’s possible that the coup attempt might change things. The coup made Erdogan, previously the authoritarian villain, look like he was the defender of Turkish democracy. It also created fears of instability that might make people more amenable to his strongman pitch.

That’s the biggest fear for Turkey watchers right now.

The failed coup "will clear the way for total domination of Turkish politics by Erdogan," Dani Rodrik, an economist at Harvard, told my colleague Ezra Klein last night. "It will make it easier for him to make the constitutional changes he wants to make himself essentially the one and only politician deciding everything in the country."

So while mass bloodshed may be unlikely, a more insidious risk — that the coup ushers in the death of Turkish democracy — is very much on the table.