Holding hands as they walked to vote in London’s Methodist Central Hall polling station, David Cameron and his wife Samantha surely never thought that their next joint public appearance would be 24 hours later as he announced that his family was to leave Downing Street.

Indeed, buoyed by opinion polls, favourable bookies’ odds and the reassurances of sycophantic aides, Cameron spent the rest of Thursday in No 10, quietly confident of a victory for Remain. He had lunch in the prime ministerial flat and held meetings with his ministerial colleagues.

With the supreme arrogance of a man who’s been described as an ‘essay crisis’ Prime Minister (because he does everything at the last minute and somehow manages to pull it off), it scarcely occurred to him that his premiership was unravelling.

Holding hands as they walked to vote in London’s Methodist Central Hall polling station, David Cameron and his wife Samantha surely never thought that their next joint public appearance would be 24 hours later as he announced that his family was to leave Downing Street

What’s more, reports throughout the day of a high voter turnout encouraged Cameron to believe that this signalled that younger, pro-Remain supporters were voting and thus they would come to his rescue against the usual hard core of older voters who were known to be more pro-Brexit.

At around 3pm, Cameron’s team took a phone call which made them convinced that victory was in the bag.

Lord Cooper, a co-founder of the Populus polling company and the architect of the PM’s policy on gay marriage, called to say he thought the margin of victory for Remain would be 60/40. A few hours later, Populus published its final poll of the campaign – giving Remain a commanding ten-point lead.

Not surprisingly, the findings triggered premature celebrations among the No 10 team. With presumptuous misplaced confidence, political adviser Laura Trott (one of the most senior women in Cameron’s ‘kitchen cabinet’) briefed every special adviser working for pro-Remain Cabinet ministers that the Government was home and dry.

‘The word swept through Downing Street like wildfire,’ an MP told me. ‘They were particularly ecstatic because they assumed that was the end of Boris Johnson and his leadership ambitions.

‘Some of Cameron’s team also bragged how the expected result showed that the influence of newspapers such as the Daily Mail was now in decline.’ The fact that Cameron believed Lord Cooper’s poll is a mystery. For Cooper has a terrible track record of predictions.

At the General Election, he had sneered at the tone of the Tory campaign, run by the Australian Lynton Crosby.

Cooper’s own polling suggested that Cameron would not be re-elected to No 10. Of course, it turned out to be the best Tory result for more than 20 years.

How ironic, therefore, that it was word of a private poll by bankers Merrill Lynch (which predicted a Leave win by the slenderest margin of 0.5 per cent) that led to the first cracks of doubt. Spirits were lifted around 10.15pm when the hated Nigel Farage appeared to concede defeat.

Cameron, who habitually likes to go to bed by 10.30pm, after the 10pm news, and gets up at 5.45am to work on his red boxes, decided to stay up to watch some of the first results on TV.

It was when Newcastle voted by a slim majority to Remain that there was a dawning realisation in the Downing Street bunker that he might be in trouble.

Sombre: Remain supporters including Education Secretary Nicky Morgan, far right, watch the results at Royal Festival Hall

At 12.20am, it was the much more decisive trouncing of Remain in another Labour stronghold, Sunderland, that sent tremors through No 10.

In growing panic, Cameron spoke to George Osborne and his long-time crony (and tennis-playing chum from their Oxford University days) Lord Feldman.

For her part, Samantha Cameron veered between deep distress and bouts of ice cold fury. ‘She felt terribly let down by friends who had convinced her this would not happen,’ I’m told.

Michael Gove, whom the Camerons used to count as a close friend before he declared for Brexit, was the target of much of the anger.

Unlike Ed Miliband, at the last election Cameron had prepared a speech on polling day to deliver in case he lost. But he hadn’t made any such contingency this time. Now, he realised there was no chance of getting any sleep.

As the scale of his humiliation became clear, Cameron decided to write a resignation speech. Helping him was Craig Oliver, his communications secretary, and Ed Llewellyn, his loyal fellow Old Etonian chief of staff.

Before walking out of the door to deliver the speech at just after 8am, an emotional Cameron spoke with his children and arranged for a phone call to be made to Buckingham Palace to inform the Queen that he, the 12th Prime Minister of her reign, was standing down.