After agreeing a revised Brexit deal with the European Union (EU), Boris Johnson now has to convince MPs to vote for it in Parliament to fulfil his pledge for the UK to leave the EU on 31 October.

The agreement negotiated by Theresa May was voted down three times. So how might the numbers stack up for Mr Johnson? The BBC's political research unit has got its calculator out.

How many votes does he need?

There are 650 seats in total in the House of Commons. The Speaker, who presides over the House of Commons and decides who gets to speak, and three deputy speakers, do not, by convention, vote.

Seven Sinn Fein MPs do not vote either as they choose not to take their seats on political grounds.

Assuming every other MP votes, then Boris Johnson needs 320 votes to give his deal a majority.

If any MP decides not to vote or "abstains" - then the number needed for a majority would come down.

Who could vote for it?

Not these parties: the Scottish National Party (SNP), Liberal Democrats, the Independent Group for Change, Plaid Cymru and the Green Party. They have all said they will vote against the deal.

The Northern Irish Democratic Unionist Party (DUP) has said its 10 MPs will all vote against the deal but the government is still trying to persuade them otherwise.

The other groups that Mr Johnson needs to sway are:

Labour MPs who might rebel against the party line

The European Research Group (ERG) of Conservative Brexiteers

Conservative MPs expelled from the party in September, most of whom backed Theresa May's deal

While Labour also plans to tell its MPs to vote against the deal, the BBC is aware of 12 Labour MPs who say they are planning to, or are very likely to, defy party orders and back Mr Johnson's deal.

There are another 12 who are currently undecided - mostly MPs in Leave-voting constituencies who want a deal but aren't impressed by the deal on the table. We'd probably expect most of these to vote against although we can't be certain.

Then there are the Independents. It seems likely that most of the 21 former Conservatives who were kicked out of the party (or in parliamentary language had "the whip withdrawn") are likely to back the deal - but some are expected to vote against and a handful are undecided.

A number of them are also expected to back the Letwin amendment which would withhold approval of the deal, until the legislation to enact it was safely passed (a move that would trigger the "Benn Act" and force the prime minister to request a further postponement of Brexit until 31 January).

There could also be some support from ex-Labour independents. For independent MPs we think there could be five undecided.

Among current Conservative MPs, Boris Johnson has won over 15 of the ERG who previously rejected Theresa May's deal three times.

There are another ten Conservative MPs (mostly ERG too) who are undecided. We'd probably expect most of these to back the deal although, again, we can't be certain.

All of that gives 312 MPs currently planning to vote for the deal and 303 currently planning to vote against.

That leaves 24 MPs who are undecided, or unwilling to say anything.