Imagine the scenario. Britain has been wiped out by a surprise nuclear attack.

The prime minister has been killed. Should Britain's nuclear submarine fleet launch its own missiles in retaliation?

It's a decision that will hopefully never have to be made.

But one of the first things Theresa May had to do when she became prime minister was to write her "letters of last resort". This is Newsbeat's guide to what's in them.

The letters are one of the most secretive parts of the UK's nuclear programme, called Trident.

So we've got Matthew Seligmann, Professor of Naval History at Brunel University, to help explain them.

When were the letters first written?

"The need for the letters arose as soon as we had our own submarine-based nuclear deterrent," says Prof Seligmann.

The UK has four submarines capable of carrying Trident nuclear missiles.

Since 1969, one of those subs has always been on patrol, gliding silently through the world's oceans.

Who writes them and what do they say?

Every prime minister has to write four letters - one for each submarine. They are addressed to the Royal Navy commander on board. They are usually handwritten.

The letters are locked in a safe aboard the submarine and destroyed, unopened, every time a new prime minister comes into office.

It's not known exactly what they say.

"There are only so many options available," says Prof Seligmann

"Do nothing, launch a retaliatory strike, offer yourself to an ally like the USA or use your own judgement.

"Essentially, are you going to use the missiles or not?"

Tony Blair reportedly "turned white" when he was told he had to write the letters when he became PM.

When are the letters opened?

"The submarine has to make a judgement that the UK has been hit by a nuclear strike," according to Prof Seligman.

"The commander does that by trying to make contact with the UK via Naval Command or listening out for radio signals."

It's thought one of the key tests is whether the Today programme on BBC Radio 4 is still broadcasting.

If all the checks fail, the commander will go to the safe, remove the letter and find out what the orders are.

Has anyone read one?

Trident is supposed to be a deterrent - so it's vital the enemy doesn't know how the UK would respond to an attack.

"Prime ministers don't tell you what's in the letters because it would negate the uncertainty of the deterrent," says Prof Seligman.

"Jeremy Corbyn announced publicly that he wouldn't use the missiles if he became prime minister. This caused some consternation as it eliminated the element of doubt needed for the deterrent to be effective."

James Callaghan was prime minister from 1976-1979. He's the only former leader to reveal what he would've done.

"If we had got to that point where it was, I felt, necessary to do it - then I would have done it," he told a BBC documentary in 1988.

"I've had terrible doubts of course about this. And I say to you that if I had lived after having pressed that button, I would never, never have forgiven myself."

Find us on Instagram at BBCNewsbeat and follow us on Snapchat, search for bbc_newsbeat