A striking feature of the failed military coup in Turkey is that President Erdogan and his government did not know that there was an extensive conspiracy within the armed forces aiming to seize power.

It was widely assumed that the era of military coups in Turkey was over and the army has recently had good relations with Mr Erdogan.

It may only have been a faction within the military, but it was able to strike in multiple places in Istanbul, Ankara and elsewhere, even detaining the Turkish chief-of-staff Gen Hulusi Akar for several hours until he was freed by anti-coup troops.

His headquarters in Ankara were still being reportedly held by pro-coup forces on Saturday morning.

At the height of the coup, tanks closed the bridges over the Bosphorus and members of parliament in Ankara were hiding in the cellars of their assembly building in Ankara as it came under fire.

Pro-coup helicopters were strafing the intelligence headquarters and one was shot down by an F-16. The government was eager to declare that the coup had been smashed, but there are still signs of official nervousness with Turkish airspace around Istanbul being closed, opened and then closed again.

The coup was never likely to succeed once it had lost the advantage of surprise, which it did fairly rapidly as news spread of what had happened.

The plotters failed to eliminate, detain or isolate President Erdogan who was on holiday in Marmaris from which he was able to use a reporter’s phone to communicate with a television studio and call for people to take to the streets in opposition to the coup.

He followed this up by flying to Ataturk Istanbul airport, where he was well placed to show that he was still in command.

In pictures: Turkey coup attempt Show all 17 1 /17 In pictures: Turkey coup attempt In pictures: Turkey coup attempt Turkish President Erdogan attends the funeral service for victims of the thwarted coup in Istanbul at Fatih mosque on July 17, 2016 in Istanbul, Turkey Burak Kara/Getty Images In pictures: Turkey coup attempt Soldiers involved in the coup attempt surrender on Bosphorus bridge with their hands raised in Istanbul on 16 July, 2016 Gokhan Tan/Getty In pictures: Turkey coup attempt A civilian beats a soldier after troops involved in the coup surrendered on the Bosphorus Bridge in Istanbul, Turkey, 16 July, 2016 REUTERS/Murad Sezer In pictures: Turkey coup attempt Surrendered Turkish soldiers who were involved in the coup are beaten by a civilian Reuters In pictures: Turkey coup attempt Soliders involved in the coup attempt surrender on Bosphorus bridge Getty In pictures: Turkey coup attempt Supporters of Turkish President Recep Tayyip Erdogan wave flags as they capture a Turkish Army vehicle Getty In pictures: Turkey coup attempt People pose near a tank after troops involved in the coup surrendered on the Bosphorus Bridge in Istanbul, Turkey, 16 July, 2016 Reuters In pictures: Turkey coup attempt Turkish soldiers block Istanbul's Bosphorus Brigde Getty In pictures: Turkey coup attempt A Turkish military stands guard near the Taksim Square in Istanbul Reuters In pictures: Turkey coup attempt Pierre Crom/Twitter In pictures: Turkey coup attempt Turkish soldiers secure the area as supporters of Recep Tayyip Erdogan protest in Istanbul's Taksim square AP In pictures: Turkey coup attempt People demonstrate in front of the Republic Monument at the Taksim Square in Istanbul Murad Sezer/Reuters In pictures: Turkey coup attempt Turkish soldiers detain police officers during a security shutdown of the Bosphorus Bridge Reuters In pictures: Turkey coup attempt Turkish Army armoured personnel carriers in the main streets of Istanbul Getty In pictures: Turkey coup attempt Chaos reigned in Istanbul as tanks drove through the streets EPA/TOLGA BOZOGLU In pictures: Turkey coup attempt Turkish President Tayyip Erdogan speaks to media in the resort town of Marmaris Reuters In pictures: Turkey coup attempt Supporters of President Erdogan celebrate in Ankara following the suppression of the attempted coup Reuters

The plotters made a strong effort to gain control of the media, trying to storm the national satellite communications centre at Golbasi near Ankara. This led to fighting in which 42 people were killed before the pro-coup forces were repulsed. They temporarily entered the offices of TRT state television and compelled an announcer to read out a text notable for its vagueness describing themselves as the Peace at Home Movement. It accused the government of eroding the democratic and secular rule of law and said country would be run by a "peace council" that would ensure the safety of the population.

The pro-coup forces later withdrew, but it would have been difficult in any case for them to have closed down or taken control of the many TV channels and other media outlets unless they had the full support of all the Turkish military.

The political affiliation of the leaders of the coup is still unclear though President Erdogan was quick to blame it on the movement of Fethullah Gulen, which his government commonly calls “the parallel state structure”.

This may well be so, though in the past the army has been seen as the stronghold of secularism. So far 1,563 soldiers have been arrested including five generals and 29 colonels, the detentions being carried out by the police who, unlike the gendarmerie, remained loyal to the state.

The air force also opposed the coup from an early stage, shooting down two helicopters. The Turkish Prime Minister Binali Yildirim gave a suspiciously precise figure of 2,839 for the number of officers and rank-and-file taking part in the attempted coup, but this sounds too few given the number of incidents.

Even military coups require strong support from some sections of society if they are to succeed and all the evidence is that the plotters did not have an active political constituency.

This is despite the fact that Turkey is deeply divided between supporters and opponents of President Erdogan and his AKP party and between Turks and Kurds.

But it was never likely that even those who have been targeted by Mr Erdogan would rally to a military conspiracy given their hostility to the dominant influence the Turkish military wielded from the foundation of the republic until a few years ago.

The government is presenting what has happened as a triumph of popular opposition, Mr Yildirim praising with some justice “the 15 July Festival of Democracy”.

No doubt Mr Erdogan will now purge the army of any potential opponents and to solidify his grip on all the security forces. Yesterday he claimed the coup plotters had tried to kill him and said that "they will pay a heavy price for this. This uprising is a gift from God to us because this will be a reason to cleanse our army."