jmch,
I don't know actual details. And obviously the nuclear deterent is an extreme example of numbers of ships required to fulfill a role. But In the 30-40 year life of a boat it's going to have several year-long (or even multi-year) periods out of commission for major systems upgrades. They used to have to refuel the reactors, or just replace the whole damned thing, but I think Astute is supposed to have its entire lifetime's fuel aboard - so that's one less long refit.
You've also got shorter periods of maintenance, probably because they can run for so long without it. Systems will fail the longer your cruise is, due to constant use, and you can do some running-repairs or switch to back-ups. Plus there's probably all sorts of upgrades to onboard systems that are quick, but still require some time out of commission.
Then you've got to have training periods - and in the case of Trident they have to wander over to the US every so often for test-firings and to swap old missiles for new. We no longer do maintenance in Blighty, as we did with Polaris, because the missiles have a longer "shelf life" - so it was easier not to bother - minor maintenance can be done from within the sub.
So to have one boat permanently on patrol, you've probably got one in long-term maintenance of some sort or another, one working-up and training to take over and the last one recovering from its last trip.
That leaves some margin of error for accidents, such as a major breakdown or crashing into another sub - or the land. Where you'll have to sortie the boat on work-ups and then hurry the other one out of short-term maintenance - to make sure you're covered. Supposedly we've never not had a boat on patrol (like the MoD would tell us), but 4 gives a tight margin of error if two boats were to have unexpected maintenance issues simultaneously.
All this is brilliantly covered in Peter Hennessy's 'The Silent Deep' - which is about the RN's Cold War submarine program. He's a constitutional historian who got into the Cold War and nuclear policy via that route, and I'd also highly recommend his 'The Secret State' - about the early Cold War and British government reaction to it. His books are proper academic histories, so can get a bit heavy at times - especially when you get into chapters on nuclear policy debates, but he's a witty writer when he can be, and likes to get in a good story or two as well as the dry analysis of cabinet papers.