Reports said he was on holiday at the Aegean resort of Marmaris, deep in Turkey's south-west.
Large crowds greeted Erdogan as he emerged from a vehicle at Istanbul's Ataturk Airport.
The moment he touched base in Istanbul it was clear the government was regaining control and had the support of senior military figures. A bomb exploded on Turkey's parliament complex in Ankara. He told them: "They have pointed the people's guns against the people".
Dundar said officers from the Air Force, the military police and the armored units were mainly involved in the attempt.
Turkey's intelligence agency had declared the coup over in the early hours of the morning, and said the Air Force was responsible.
They exhausted to establish a "peace council" and announced there would be martial law.
In images broadcast on CNN-Turk, dozens of soldiers walked among tanks with their hand held up, surrendering to government forces on Istanbul's Bosporus Bridge.
But the plotters' control of media outlets was not to last and even before he had arrived at Ataturk airport President Erdogan contacted CNN Turk and appeared in a video call, urging Turks to take to the streets.
The president may have been lucky.
Possible theories behind the military coup:Erdogan making enemies with the Western Allies.
The exiled Syrian opposition has congratulated the Turkish people for halting an attempted military coup.
Tanks took to the streets and the bridge across the Bosphorus in Istanbul was taken over.
The Pentagon said the coup attempt had so far made no impact on the Incirlik air base, and said anti-Islamic State air operations from Incirlik are continuing.
Reuters reporters saw a helicopter open fire in Ankara.
Erdogan, who had been holidaying on the coast when the coup was launched, flew into Istanbul and was shown on TV appearing among a crowd of supporters outside the airport, which the coup plotters had failed to secure.
There was no political or public backing either.
A coup against the democratically elected government could make it hard for the United States to continue to cooperate with Turkey.
They are a faction within the army, and military figures say they are a small group within the First Army, whose headquarters is in Istanbul. In a statement provided by his office, he said: "They will pay a heavy price for their treason to Turkey".
British Foreign Secretary Boris Johnson says he has spoken to his Turkish counterpart, Mevlut Cavusoglu, to underline support for Turkey's "democratic elected government and institutions" after an overnight coup attempt.
Could it have all been planned in America?
President Erdogan has for years accused a former ally, Fethullah Gulen, of plotting against him.
The Gulen movement itself denied involvement.
Gulen has rejected any responsibility and condemned the attempted coup.
An officer recently removed from his position as a legal adviser with Turkey's military chief of staff, identified as Muharrem Kose, is the key figure behind planning the ongoing coup attempt in Turkey, reported news agency Anadolu.