ES News email The latest headlines in your inbox twice a day Monday - Friday plus breaking news updates Enter your email address Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid You already have an account. Please log in Register with your social account or click here to log in I would like to receive lunchtime headlines Monday - Friday plus breaking news alerts, by email Update newsletter preferences

Two vignettes reveal the fine-tuning behind Boris Johnson’s leadership campaign.

After Dominic Raab crashed out with 30 votes — three too few — his campaign manager Sir Hugo Swire admitted the numbers came as “a surprise and a big disappointment”.

“They say there’s nothing more sophisticated than the British politician at work when it comes to an election,” grumbled Sir Hugo, “clearly some people who said they were supporting us weren’t.”

By contrast, Johnson was handed a sealed envelope by his “spreadsheet guy”, former Tory chairman Grant Shapps, before each of the votes, with instructions to open it after the result was announced.

In round one, Johnson duly found the number 114 written in ballpoint pen under the flap — an exact prediction of the number of votes achieved. The same trick was repeated in every round.

“We not only knew exactly how many votes Boris had, we knew precisely how many the other candidates had as well,” said a senior source.

The Standard has been behind the scenes to see how this political feat was pulled off by a team that took the art of “vote counting” to new levels of sophistication.

The findings are eye-opening, especially with claims swirling that Team Johnson knocked out Michael Gove by “lending” votes to Jeremy Hunt.

At its heart is a unique database of over 3,000 pieces of information about the 313 Conservative MPs and how they might vote.

Created by Shapps using a cloud-based spreadsheet, it linked to other databases, including call logs and even Mr Johnson’s nightly to-do list of MPs to phone from home.

Shapps began planning after the winter debacle when Jacob Rees-Mogg’s ERG army botched a confidence vote in Theresa May and seemed surprised when she won.

He started by re-reading Robert Caro’s great biography of Lyndon B Johnson, which describes how the 36th US president amassed influence by predicting Senate divisions through meticulous research, rigorous cross-checking and multiple sources.

While President Johnson relied on paper lists, Shapps created a multi-layered colossus. However, he adhered to LBJ’s rules: Assume everyone is against you unless proven otherwise; Never mistake agreement for a vote in the bag; And cross-check everything.

Shapps insisted on three sources for verification, and added a “believability weighting” for data, adapted from investor Ray Dalio’s book Principles.

The system grew in complexity. Each MP was listed by name, constituency, year of election, contact details, and the percentages of Leave and Remain voters in their seats. A comments section recorded their intentions and worries.

The most important boxes recorded how the MP was believed to be voting: A figure 1 meant 100 per cent certain, but some were put down as 0.5 or 0.75.

To make such judgment calls accurately, vast quantities of intelligence were needed. This poured in with the arrival of former Chief Whip Gavin Williamson.

Williamson ran a team of 64 “handlers” (over 80 by the end) who spent weeks talking to MPs, constantly checking how they planned to vote.

Some handlers were not MPs, but active in politics. Some acted as evangelists, others simply recorded what they heard.

“Gavin knew exactly who was the best person to speak to any given MP,” said a source.

The other key appointment was former MP James Wharton as campaign manager.

Four months ago the Boris campaign was little more than dinners hosted by Rees-Mogg.

Wharton forged a professional unit, staffed full-time, and persuaded ex-minister Mike Penning to swap offices, making his grand suite at Portcullis House a showroom for the candidate’s meetings.

By the time MPs started voting, Team Johnson had at least seven sources of intelligence about each of the 313 MPs. It even generated a daily list of people for Mr Johnson to meet or phone, complete with briefing notes.

To avoid “confirmation bias”, where candidates believe what they want to hear, even fulsome pledges of support to his face were triple-checked.

Time-wasting was slashed. Two MPs were overheard ostentatiously complaining they had been ignored by Mr Johnson.

But the system warned, correctly, that they were on a rival team. A red herring that might have gobbled up candidate time was avoided.

It may never be proven whether vote-lending took place. But the accuracy of the system suggests the capability was certainly there.

Given the scale of Boris’s victory, the immense effort might seem like overkill. But memories are still fresh of the 2016 fiasco when he outsourced management to Gove.

For 2019, Johnson assembled his own team of giant-killers. For a potential prime minister, it was a good start.