Before Turkish soldiers filed into central Ankara and Istanbul on July 15 many believed the days of Turkish military coups were long gone.

It had been almost 20 years since the last of Turkey's four successfully military coups in 1997 and even much of the opposition praised President Recep Tayyip Erdogan for having finally brought the Turkish army under civilian control.

The coup took observers and Turkish residents alike by surprise, both in its emergence and its bloody execution. Yet by morning it was all over and the government had survived. More than 8,000 people have since been detained in a post-coup crackdown.

Some more creatively-minded Turkish citizens have since suggested that this may have been a "fake coup," a piece of theatre (#darbedegiltiyatro), organized by Erdogan himself to consolidate power.

The evidence does not bear this out. Far from being half-hearted, the strategy of the coup was solid and comprehensive and the execution - despite being ultimately unsuccessful - was not maladroit.

Close call

As most coups are, this was a close-run thing. The plotters struck swiftly, with total element of surprise, and had just one or two key encounters in the course of the coup gone for rather than against them, they may very well have succeeded in temporarily seizing state power.

The coup forces were numerous and had successfully infiltrated the military establishment to a remarkable degree. The coup was led by three of the country's most senior 4-star generals: former Air Force commander Akın Öztürk, 2nd Army General Adem Huduti and 3rd Army General Erdal Ozturk. The Turkish authorities have since detained a total of 103 military officers with a rank of brigadier-general or higher (almost a third of all Turkish generals).

Military coups have a long history in Turkey, the last successful one happened in 1997

The coup forces sent dozens of independent strike teams to secure key targets in both politically important urban centres. They succeeded in quickly arresting and neutralizing the Army chief of staff, the head of the Airforce, the head of the Navy, and the head of Gendarmerie. They seized the Army headquarters and the headquarters of the Gendarmerie. They seized the state television and radio broadcaster and the key transport choke-points in Istanbul and Ankara. They seized enough armour and air power to have a huge fire-power advantage over the scattered and headless loyalist government forces.

So why did they fail?

Three major failures were primarily responsible for the defeat. First and most significant was the early failure of an airborne coup strike team to capture Erdogan himself, who escaped with minutes to spare.

Second, while the coup forces moved quickly on the presidential palace in Ankara, they appeared to have underestimated the palace defences, were stalled in a bloody pitched battle, and ultimately failed to seize the presidential palace itself which if captured would have acted as a tremendous rallying symbol for holdouts in the security services.

Third, the coup plotters had not sufficiently infiltrated or co-opted the police force, the first line in the professional defences of the state. During the first few hours of the coup the police largely remained neutral, neither moving with nor against the coup forces except where they were directly attacked. They moved strongly against them once it became clear Erdogan had not been arrested.

Erodgan escaped capture with minutes to spare

In addition to these three primary failures, the coup forces also made a number of more minor missteps.

They had failed to co-opt or neutralize the Turkish religious establishment, which ordered mosques across the country to mobilize popular street resistance. They failed to arrest Prime Minister Binali Yildirim and Interior Minister Efkan Ala, and to secure the Interior Ministry headquarters in Ankara. They were slow to seize private television broadcasters. And they underestimated the strength of the Osmanli Ocaklari, ruling AK party irregulars who formed the backbone of popular resistance and could have organized violent street resistance.

Unfavorable conditions

Ultimately the conditions internal to Turkish society were not favorable for a coup, with even traditionally coup-sympathetic constituencies such as the domestic business elite and upper social class strongly opposed to the current government's overthrow. For this reason even had the coup forces prevailed, they would have struggled to maintain control of the state without risking a protracted and bloody conflict.

But in the short run one cannot conclude that the coup was sloppy, half-hearted, or a hoax merely because it failed. Seizing control of a country as large and complex as Turkey is not easy. Overall, military coups have a success rate of around 50-50 with the chance of success greater in smaller and less advanced societies.

Had the helicopter strike team targeting Erdogan arrived a few minutes earlier, or the presidential palace strike team prevailed in Ankara, the story of the July 15 coup might have been quite different.