One of the first tasks of a new British prime minister is writing four letters. These "Letters of Last Resort", each identically worded and written by hand after a briefing on the destructive power of the Trident missile, are sealed and delivered to the four British Vanguard class submarines. They contain instructions on what to do in the event of nuclear war, and will only be opened if the submarine's crew determines that Britain has suffered an attack and no orders are forthcoming. If this doesn't happen, they will be destroyed unopened when the next Prime Minister takes office.
One of the chief problems of any nuclear deterrent is that both the weapons themselves and the command-and-control infrastructure will be prime targets for an enemy's nuclear weapons. The first problem is relatively easy to deal with, and most countries solve it by sending some of their nukes to sea aboard submarines, which are by nature difficult to find. The British, in fact, like this approach so much that they chose it for their entire nuclear arsenal. But nuclear weapons aboard a submarine, while fairly safe, are also of little use if orders to fire them can't be given. The US solves this with a massive command-and-control infrastructure, including not one, not two but three different converted airliners. But there are two problems with this kind of system from a British perspective. First, it's really expensive, and the British can't afford US defense budgets. Second, Britain is considerably closer to potential threats, who should remain nameless but who I will assign the randomly-chosen name "Russia" to, than the US is. This gives even less time to get a message off to any nuclear forces, to say nothing of the problems of communicating with SSBNs.
Obviously, Britain has some infrastructure to get messages to the Continuous At Sea Deterrent. The system is centered at Northwood in the suburbs of London, which in the late 60s was linked to Downing Street by a two-way closed-circuit television system, tested daily. Unlike the US, Britain didn't have a clear constitutional line of succession, so the Prime Minister designated a pair of "nuclear deputies" that would be empowered to make decisions in an emergency. But by the early 70s, the threat of a Soviet "bolt from the blue" taking out the entire command and control infrastructure was simply too great, and a uniquely British solution was found.

Each submarine would be issued with a sealed letter from the Prime Minister, with instructions that it be opened if it appeared to the crew that Britain had been the victim of a nuclear attack and the country was effectively destroyed. A number of indicators have been given for this, the most famous (and most curious) being the absence of the long-wave broadcast of the BBC's Radio 4. If it looks like Britain is gone, then the letter will be opened, revealing which of the four potential options the Prime Minister has taken: 1. Retaliate 2. Don't retaliate 3. Don't do anything yet, but see if you can find a surviving friendly government (the US and Australia are frequently mentioned) and place yourself under their control 4. Use your own judgement
Whichever option is taken would probably be the last official act of His Majesty's Government, and might not even have been by the current Prime Minister. Switching out the letters while a boat is on patrol is obviously impossible, and Tony Blair was rather irritated that one submarine that departed shortly before he took office in 1997 would carry John Major's letter, but the deployment and political schedules don't always align.1 As the use of the letters has thankfully been unnecessary and retired PMs are understandably reluctant to speak on the matter, the only man whose letters we have any insight into is Jim Callaghan, Prime Minister from 1976 to 1979, who hinted in an interview that he would have ordered retaliation.

Jim Callaghan
But all of this requires that the British think about nuclear weapons in a fundamentally different way from the United States. The United States makes extensive use of "Permissive Action Links", devices that block the use of nuclear weapons unless a code, known only to higher headquarters, is passed to the unit with the bombs. This was set up to relieve Kennedy/Johnson/McNamaraite fears of some unit in the field flying off the handle and starting WWIII, but means that an extensive and robust communications infrastructure is required to make sure America's nuclear arsenal isn't suddenly rendered useless by a nuclear strike.2 The British have instead chosen to place their trust in the officers and men of the Royal Navy. In theory, if the entire crew of one of the Vanguards went crazy together, they could launch their missiles, but in practice, this threat is minuscule. The launch procedure requires several officers to work together, and even if they were to form a conspiracy to do so without being noticed,3 it's almost certain that other members of the crew would interfere if they hadn't gotten proper orders or the confirmation that the Letter of Last Resort was necessary.
As this goes out, Keir Starmer's letters are about to be recalled and destroyed, and Andy Burnham will sit down to write his version. I hope and pray we never find out what is in them, or any of those written by his successors.
1 I looked into whether or not Liz Truss, who served for only 50 days in 2022, ever got a letter to sea, and the answer wasn't entirely clear. Patrols in 2022 were running to something like 130 days, so statistically she probably didn't, and internet rumors suggested the same. ⇑
2 This is the reason that the American PAL codes were famously set to all 0s for many years. The military knew that Dr. Strangelove was fiction, and wanted to be sure they wouldn't be stuck with dud bombs if something happened to Washington before the codes went out. ⇑
3 And this is unlikely because, deep down, very few people want to destroy the world. ⇑

Comments
Suicide bombing has achieved notable geopolitical success (if not personal success) so the 3rd footnote might be an assumption that deserves revisiting.
Apart from the one choice of non-retaliation, how does option 2. continue? How does it differ from option 3. in particular?
The setup is also rather odd. I'm not sure what genre of film does the plot "some random third party -- not Russia -- nukes Britain; in reaction, Russia sets up a fake BBC Radio 4" fall into.
Option 2 probably ends with something like "...and scuttle your ship full of evil hell-bombs, which were only ever meant to be a bluff and now can serve no good purpose".
That's rather different than option 3, "...and go nuke whoever Donald Trump or Tony Albanese tells you to".
In both cases with more flowery phrasing that praises the honor and loyalty of the crew, of course.
@Matt C
I think those are completely different. Your typical suicide bomber is pretty deeply ideological. He believes a story where what he’s doing is going to make life better for someone he cares about. To pick an obvious example, your typical kamikaze pilot was told “if we do this enough, we will drive the Americans to make peace on terms favorable to us”. Obvious benefit is obvious, particularly if you’re raised in the cult of the Japanese state.
But that doesn’t really work for anyone who is able to give orders to a great power’s nuclear weapons today. Sure, you might be able to trigger WWIII, but how does that help the things you care about? This is obviously going to make things worse.
(Also worth noting that even if one person decides they want to blow up the world, other people are likely to disagree, and stop them.)
@Basil
It’s the difference between showing up off the US coast and saying “If there’s anyone home, we have some weapons for you” and going to New Zealand, throwing the codes over the side and asking if they’d like to strip anything from the boat.
I do like the idea of Russia having to set up a fake BBC Radio 4.
Hmm, wackiest Letter of Last Resort: "If you're reading this, Parliament has obviously cocked things up, so remember that your true loyalty is to the Crown. Westminster is probably a smoking crater, so head over to Montecito, see if you can find King Harry and ask him for your next orders".
Citation heavily required here. Suicide bombs have never achieved geopolitical success on their own. Yes, in the context of an ongoing insurgency, where the majority of attacks are carried out by other means, suicide bombs can be a way to attack specific high-value targets not reachable by other methods. But that's a very different situation than a small group of submarine officers deciding to pre-emptively launch a nuclear attack. That sort of scenario would be much closer to 9/11 than the Iraq insurgency, and 9/11 was not a geopolitical success for Al Qaeda.
To me that raises the question, if that's the case, should the crew follow orders? Presumably, if things are to the point where letters of last resort are being opened, there isn't going to be enough of a government left to court-martial the crew should they ignore Option 2, and, instead, for example, choose Option 3 by contacting the US.
If the lawfully elected government and its military commander in chief determine that the proper role of the British nuclear arsenal is to serve only as a bluff and to never be used, that is their decision to make. The crew should absolutely follow their orders, if those are their orders. The only way Letters of Last Resort can work, is if the crew can be trusted to obey their lawful orders even if they could get away with breaking them.
@JohnSchilling and @bean
Option 2 still makes no sense.
@quanticle The factions using suicide bombers have achieved far more success in the 21st century than they did in the 20th.
@Basil
The obvious moral case for Option 1 is "We built these as a deterrent, and we should pre-commit to using them, because that's how you deter people". The moral case for Option 2 is "Britain is gone. The deterrent has already failed. Killing more people at this point won't achieve any reasonable goal, and there's been enough death." Note that this can be a reasonably coherent point even if you support the deterrent and might even use some of it in other situations where it would make a difference.
@john schilling
you say wackiest, I say "the one sir humphrey is most likely to write"
Is there an understanding of how this works for the non-Anglo SSBN operators (France is probably the easiest to get information on, and I assume China and Russia are very heavily top down -though maybe distrust in their communication systems ends up delegating a lot of authority to turn keys downwards)
@bean
It's not a matter of morality. It's a matter of math (game theory, or perhaps decision theory).
I mean, if someone has a moral problem with nukes and wants a conventional-only military (or is an outright pacifist), that is a coherent position that a reasonable person can hold.
If someone is interested in "nukes on the (relatively) cheap" so that they can do, shall we say, "active deterrence" (i.e. rattle a nuclear saber), but is not interested enough in a survivable second strike to properly pay for it, they can absolutely have a launchpad-based ICBM force, or perhaps a dispersed road-mobile TEL force. This, too, is a coherent position, and AFAIK several states have indeed chosen to (for the time being) pursue a subset of the triad that doesn't include SSBNs.
But choosing to spend the money to get a better survivable second strike capability, and then choosing to throw it away, is simply stupid. It would be just as if a state decided to -- in the name of protecting the environment -- make it difficult for itself to do any of the things that would protect the environment; and, having made it difficult for itself, it spent a fortune and a decade to assemble by eminent domain a long straight continuous strip of land, then turned around and on a whim cut it up and sold it for peanuts and allowed people to build stuff on it.
@Basil, morality and game theory are not the same for a great many people.
Spending the money to get a survival second strike capability is most definitely worth it IF you never have to use it. That's the point of deterrence.
If deterrence fails, what will launching a few British nukes as a second strike actually achieve? It may not lead to nuclear winter, but dumping more radioactive crap into the atmosphere is quite likely bad for everyone. It will make life even worse (if that's possible) for any British survivors, worse for any British allies, worse for neutrals.
It's hard to sort out the role of Britain's SSBNs specifically, but the cost of the Free World's SSBNs in total has already been repaid paid in full and then some, without launching any missiles against anyone. That's why we, and the Brits, built them. There may be circumstances in which it would be appropriate to launch some of those missiles, but "...otherwise we won't get our money's worth" is not one of those reasons.
@Basil
The PM writing this knows that, when the letter is opened, things are over. Britain is a smoking crater, and nothing the weapons will do will change that. So at this point, there are two reasons for a launch and cause massive death: game theory and spite. Now, most of us here are game theorists enough that we'd seriously consider the first one, but that's certainly not universal. As for spite, I'd sort of hope someone making these decisions isn't doing it for that reason.
And I will also echo John's point, that if these letters get opened, in many ways we have already wasted the cost of the system, because the whole point is that we really don't want to have a war in the first place.
@redRover
I did a bit of looking, and didn't find anything particularly interesting for France. I don't think there's enough detail on any of the other powers to be useful.