Prime ministers are appointed based on their ability to command confidence in the House of Commons. If an election produces a clear majority for one party, then the leader of that party becomes prime minister. If it is the incumbent prime minister, then they just continue in office. If it is another party, then the incumbent formally resigns the morning after the election and they are replaced.
If no party wins a clear majority, then there may be a process of negotiation before it becomes clear who is likely to be prime minister. An incumbent prime minister is entitled to remain in office and test whether they can command confidence, or they may resign if it becomes obvious that they will not be able to do so.
However, it is vital that a prime minister is in place and there is an expectation they will not resign until it is clear who can take over.
The incumbent prime minister informs Buckingham Palace that they will be resigning. There is then a well-rehearsed sequence of events in which the outgoing prime minister travels to see the Queen and formally tenders his or her resignation. They have a short audience with the Queen.
After the outgoing prime minister has left, the incoming prime minister arrives and is formally asked by the Queen to form a government. This audience is known as ‘kissing hands’. After their appointment, the new prime minister heads straight to 10 Downing Street.
The Queen’s role in appointing a prime minister is one of her remaining prerogative powers. These are residual powers remaining with the Sovereign that have not been placed elsewhere. The majority of those powers are exercised on her behalf by her ministers, but the power to appoint prime ministers remains with the Queen.
If the government hold a majority, it is for the party or parties in government to identify the successor.
If a prime minister resigns and the party in government does not have a majority, it becomes more complicated. If a clear alternative is likely to be able to command confidence, then this only needs to be made clear to the Palace. This could be through some parliamentary mechanism, but it can also be through coalition or confidence and supply agreements between parties or letters of support.
The Queen relies on party leaders deciding among themselves and making it clear to the Palace. If the incumbent prime minister resigns suddenly and there is no clear alternative, the Queen might turn to the leader of the opposition to attempt to form a government and test whether he or she can command confidence.
There is a strong constitutional convention that the Queen should be kept out of politics.
If there is no clear majority, or if negotiations over government formation have not produced a clear answer as to who can command confidence, then it is expected that political parties will establish who is best placed and ensure that the Queen is not dragged into any disputes. According to the Cabinet Manual, "the Sovereign should not be drawn into party politics, and if there is doubt it is the responsibility of those involved in the political process, and in particular the parties represented in Parliament, to seek to determine and communicate clearly to the Sovereign who is best placed to be able to command the confidence of the House of Commons".
The question of who can command confidence only arises if a party has not won a majority or has lost it during the lifetime of a Parliament.
The Cabinet Manual says that "an incumbent government is entitled to wait until a new Parliament has met to see if it can command the confidence of the House of Commons, but is expected to resign if it becomes clear that it is unlikely to be able to command that confidence and there is a clear alternative". In 1924, Stanley Baldwin resigned after being defeated on a King’s Speech
At other times, prime ministers will resign if it is self-evident that they will not be able to command confidence. In February 1974, Edward Heath resigned after a weekend attempting to negotiate an agreement with the Liberal Party. He was replaced by Harold Wilson, who led a minority Labour government. In May 2010, Gordon Brown resigned five days after the election when it became clear that negotiations with the Liberal Democrats would not produce an agreement with Labour and that the Conservatives were more likely to be able to form a coalition.
It is the role of the monarch’s private secretary, the prime minister’s principal private secretary and the cabinet secretary to maintain communication between Buckingham Palace and politicians in trying to establish who can command confidence. They are known colloquially as the ‘golden triangle’.
The Cabinet Manual emphasises that the Queen should be kept out of politics and that ensuring she is able to appoint a successor is a role that "falls especially on the incumbent Prime Minister", who may also be asked to advise her on who is best placed to be appointed. It is advice with a lower-case a.
However, 1949 civil service papers say that the monarch "has the absolute right to consult anyone he pleases" and that in a "complicated political situation" the monarch can consult more widely.
There have been a number of occasions in the Queen’s reign where she has had to make a decision on which political controversy has – or nearly has – arisen.
In July 1953, Prime Minister Winston Churchill suffered a stroke at a time when his expected successor, Anthony Eden, was undergoing an operation. Buckingham Palace had to consider options for a caretaker prime minister if Churchill died. In January 1957 and in October 1963, the Queen had to choose between the claims of different potential successors from the Conservative Party. In 1963, she invited Alec Douglas-Home to see whether he could form a government when the outgoing prime minister, Harold Macmillan, advised her to do so. This was against the wishes of other senior Conservatives who expected to be in the running and eventually led to the introduction of formal rules for how Conservative leaders are chosen.