To explore the history of Dad’s Army, you have to enter a near-military environment. Speed bumps, vehicle checks and CCTV impede the route to the building in Caversham, Berkshire, where the paperwork about the show’s creation is stored. These levels of security are because the BBC Written Archives are housed on the grounds of BBC Monitoring, whose duties include listening to global media on behalf of MI6.

But if the records of any TV show were to deserve such protective apparatus, it would be Dad’s Army, the BBC’s single most durably valuable programme. Next 31 July marks 50 years since the first episode was shown, while the last original show was screened in 1977 – but repeats still top the BBC Two ratings.

The origins of this TV phenomenon are recorded in pink folders containing yellowed press cuttings, letters from viewers and internal memos typed on paper so flimsy the letter O sometimes goes right though like a bullet hole. The first documents trace the payment of £200 each to producer-director David Croft and co-writer Jimmy Perry for a script originally called The Fighting Tigers, based on the latter’s second world war experience in the Local Defence Volunteers, later called the Home Guard.

Arthur Lowe, who was paid £170 and two shillings, as the pompous Captain Mainwaring. Photograph: PA

Most successful British sitcoms have central characters unsuited to their profession: Basil Fawlty shouldn’t be running a hotel, Del Boy Trotter overestimates his commercial savvy, David Brent is a terrible boss. Dad’s Army set the template for this comedy of overconfident incompetents. Asked to defend Walmington-on-Sea while the real men are away, bank manager Captain Mainwaring acts out a fantasy of military command. Because the Home Guard included those too old and too young to be called up, the characters’ age-range was unusually wide: from 70-year-old Lance Corporal Jones, who has fought for the British empire in Sudan, to 17-year-old asthmatic Private Pike.

The budget file for the first series shows that John Le Mesurier, as Sergeant Wilson, was initially regarded as the show’s star, and paid £209, nine shillings and sixpence, while Arthur Lowe as Mainwaring received £170 and 2 shillings. A letter from Michael Grade – later to run the BBC, ITV and Channel 4, but then a junior showbiz agent – agrees third billing and pay parity with Lowe for Clive Dunn, only 47 years old but looking twice that on screen as L/Cpl Jones.

Ian Lavender, paid £51 and 19 shillings to play Pike, was only 22 at the time, which means he is now the only surviving member of the main cast. Lavender finds the lasting popularity of the series is “a continuous pleasant shock”. He thinks the main reason is that it was written to have universal appeal. “It surprises me that no one now seems to want to make programmes that all the family can watch,” he says. “Everything is so niche-driven: shops, films, TV. If I don’t like something, nobody cares because they say they weren’t aiming at me.”

Milking it … Clive Dunn as Lance Corporal Jones in the episode Operation Kilt. Photograph: BBC

The show was an instant hit – one ​viewer ​even offered to loan them his​ 'overcoat and battledress outfit'

Although Dad’s Army is now regarded as the epitome of safe mainstream comedy – and often wielded as a corrective yardstick by those who find modern TV comedy too shocking – the show was considered controversial in 1968. Archived memos show that Paul Fox, controller of BBC One, was so concerned about potential offence to viewers who served in or were bereaved by the war, he ordered the removal of footage of Nazi troops and displaced refugees from the opening titles.

This triggered a response from Michael Mills, BBC’s head of comedy, expressing “profound disquiet over your decision”, and complaining that the changes meant the show would no longer be able “to advance comedy output into new areas”. Fox tersely replied that he did not consider Dad’s Army to be “breakthrough territory”. Lavender says he only learned about these tensions through later books and documentaries. At the time, the cast was “unaware of any controversy”.

When looking at the beginnings of a classic, the question is: “Did anyone realise?” With Dad’s Army, the TV critics mainly didn’t. Preserved in the Caversham files is the verdict of Peter Black of the Daily Mail, complaining that the first episode wasn’t “situation or character comedy, it’s only gag comedy, the easiest to write and the quickest wearing on the ear”. Michael Billington, now the Guardian’s theatre critic but then covering TV for the Times, found the show to combine “bland sentiment and humour rather uneasily”.

Yet one curling cutting in the file makes anyone who has worked as a reviewer want to stand and salute. In those days, critics phoned in reviews immediately after transmission. On that summer night 50 years ago, Ron Boyle of the Daily Express immediately declared Dad’s Army “a classic comedy series” that might even be “comedy’s finest half-hour”.

Ahead of their time … from left, showrunners Jimmy Perry and David Croft in 1989. Photograph: Jim James/PA

The show quickly became a hit with the very audience the BBC had worried about: those with direct experience of the events it depicted. Soon after the first broadcast, a Home Guard veteran signing himself Private Huntley wrote to congratulate its makers, while many others sent in ideas (“a few funny things that happened in our village”). One even offered the loan of an “overcoat and battledress outfit”.

Those early letters also reveal the cross-generational appeal that has been key to the series’ longevity. “Each of us in the house has a favourite actor,” writes a Miss Carruthers; while a viewer from Helensburgh writes: “I watch with my teenage family. They know nothing of those daft days but they enjoy the programme just the same!” Five decades on, the same applies.

By the third episode, screened on 14 August, the critics were catching up with public enthusiasm. The Western Mail called it “comedy of the very best sort, because it’s drawn from a rich fund of experience and not from the artificial hatching of a script conference”. As that insight suggests, the writer, Peter Tinniswood, was himself a comedy writer (I Didn’t Know You Cared, Tales from the Long Room). His review also makes a crucial point that had been overlooked by those making accusations of bad taste: he remembered the Home Guard being “a constant source of humour”.

On 15 August, another distinguished comedy writer, Barry Took (The Army Game, Round the Horne) sent a note to Croft: “Dear David. I think Dad’s Army is one of the funniest shows I’ve ever seen. The scripts, casting and direction are absolutely great.”

We had a line to say, and it had to be right the first time. No retakes. No one wanted to be the one who cocked up

Took’s professional eye had noted that, unusually, those three elements all involved Croft. Croft was what is now called a showrunner. That degree of individual control can be clearly seen. As is common in British sitcom, Croft and Perry favoured catchphrases but, as director, Croft could ensure there was a double kick: first from Mainwaring’s “Stupid boy!” and then from Pike’s wounded reaction. The most famous line in the series – when a German PoW demands the young private’s name and Mainwaring snaps: “Don’t tell him, Pike!” – is funny not only verbally but also visually, due to Lavender’s panicked reaction.

There was rarely time, however, to relish any particular moment, due to the pressure of studio recording. “We had a line to say,” says Lavender, “and it had to be right first time. No retakes. We were all like nervous kids as it approached, not wanting to be the one who cocked up!”

Even as ratings rose, the BBC remained nervous about the show – an early episode was cancelled after the Soviet-led invasion of Czechoslovakia. But the one persistent controversy is the feeling that Dad’s Army was spoiled by “the repeated gales of inane laughter from the unseen audience”, as one viewer put it. To such complaints, Croft politely replies that, because his main actors have stage backgrounds, live studio reaction helps them to time – and to have confidence in – the jokes. That calculation reveals Croft’s perfectionism.

I was accused of nicking the scarf from Tom Baker's Doctor Who – even though we were first

Croft’s thoughtfulness towards his performers was not always reciprocated. Memoirs have revealed that Lowe took such a dim view of the script, he would hide it behind the rehearsal room radiator, or leave it with his driver overnight because he wasn’t prepared to have it in his house. During the shooting of the first series, Le Mesurier told fellow drinkers in the BBC bar it was “going to be a complete disaster”. Lavender, though, says they kept their doubts from the rest of the cast. “I never heard either prophesying disaster, although that was a general characteristic of Le Mesurier’s humour.”

It is unclear whether the two men knew that, by the second series, Lowe was earning £420 an episode, ahead of Le Mesurier’s £367. In January 1970, Croft received a generous letter from the BBC One controller, acknowledging that he had been wrong about Dad’s Army. “Looking back to that first programme,” wrote Fox, “I am glad to say that you were 100% right.”

Five decades on, Lavender still has the knitted scarf his character’s mother gave him to protect his weak chest while on parade. “I was accused in one newspaper of having nicked the idea of the scarf from Tom Baker’s Doctor Who,” he says. “I think simple research will show that we were first. Deeply upsetting!”

Some actors can end up feeling resentful when a role comes to define them, but Lavender has no such reservations. “I feel immensely proud to have been part of the beast. We still watch it. Not every weekend but, if we’re in, yes. We do find it funny and endearing – a pleasant reminder of a gentler time.”