As excitement mounts ahead of the finale of hit US TV show Breaking Bad, Brett Martin sits in as showrunner Vince Gilligan and his writing team tease the much-acclaimed drama into life

It was an all-time record hot day in the San Fernando Valley. On West Burbank Boulevard, lined with offices and strip malls, the air shimmered; people took pictures of their cars' temperature displays: 110, 112, 116. In an anonymous building across from an AutoZone, the lobby directory showed the offices of a private eye, a dental supply company, a handful of financial companies, and, in suite 206, something blandly mysterious and vaguely sinister called Delphi Information Sciences Corporation. The plastic nameplate on the suite's door did little to illuminate the nature of what such a corporation might do. Certainly it offered no clue that behind the door, under the dropped ceilings, the fluorescent lights, and the hum of air-conditioning in this one-time data services office, was the most coveted workplace in Hollywood: the Breaking Bad writers' room.

It was so not only because Breaking Bad was arguably the best show on TV, but because its creator and showrunner, Vince Gilligan, was known as a good man to work for – someone who managed to balance the vision and microscopic control of the most autocratic showrunner with the open and supportive spirit of the most relaxed. He was a firm believer in collaboration.

"The worst thing the French ever gave us is the auteur theory," he said flatly. "It's a load of horseshit. You don't make a movie by yourself, you certainly don't make a TV show by yourself. You invest people in their work. You make people feel comfortable in their jobs; you keep people talking."

In his room, he said, all writers were equal, an approach that he insisted had less to do with being a Pollyanna than with pure, selfish practicality. "There's nothing more powerful to a showrunner than a truly invested writer," he said. "That writer will fight the good fight."

On this day, a Monday, he sat at the head of a conference table as his writers gathered for work after the weekend, chattering about the heat. Forty-three years old, he wore light jeans, an orange T-shirt and silver sneakers; his face, with its goatee and glasses, was poised at a precise fulcrum between relaxed southern gentleman – a young Colonel Sanders, maybe – and eager fantasy geek. Gilligan started his path to TV with a semi-successful career in feature films. His TV break came with The X-Files, where he rose to executive producer and penned some 30 episodes before returning to the frustrations and snail's pace of feature-film making, working on Hancock, a movie about a surly, alcoholic superhero. In the midst of the endless rewrites, in 2005, Gilligan was on the phone with an old friend and fellow X-Files writer Thomas Schnauz. The two were complaining about the state of the movie business and wondering what they might be qualified to do instead.

"Maybe we can be greeters at Walmart," Gilligan said.

"Maybe we can buy an RV and put a meth lab in the back," said Schnauz.

"As he said that, an image popped into my head of a character doing exactly that: an Everyman character who decides to 'break bad' and become a criminal," Gilligan recalled. It was a powerful enough image that he got off the phone and began jotting down notes. The heart of the show came together in a hurry. The main character, Walter White, is a mild and beaten-down high school chemistry teacher who finds himself diagnosed with lung cancer. Inadequately insured, with a baby on the way, he is desperate to provide for his family when he's gone and hits on the idea of going into the meth business with a junkie ex-student named Jesse Pinkman, played by Aaron Paul. Thanks to White's chemistry expertise and relative (by the standard of meth dealers) discipline and devotion to quality, Walt and Jesse's product becomes much in demand. Legal, familial, and moral complications ensue.

By now, the staff in the office of Delphi Information Sciences Corporation had assembled and dispensed with the first and most important task of the day: ordering lunch. To Gilligan's left, wearing a green San Diego Zoo T-shirt, sat Tom Schnauz, whose joke had inspired the show and who was now supervising producer. The fifth episode of the fourth season, 405, which was currently on the table, was his to write. Elsewhere around the table were Gennifer Hutchison, Moira Walley-Beckett, Sam Catlin and Peter Gould. One more writer, George Mastras, was out of the office, writing an episode. At the far end, across the long expanse from Gilligan, the writers' assistant and script co-ordinator, Kate Powers, sat feverishly transcribing everything said. She wore black carpal-tunnel sleeves over both wrists.

On the wall behind Gilligan was a large corkboard. Across the top were pinned 13 index cards representing the 13 episodes of the season. In rows beneath them, more neatly printed cards (Schnauz, who had the best handwriting on staff, was the deputised card writer) contained detailed story points. The cards looked like a pile of leaves that had faced a stiff, left-blowing wind, clustered deep under the early episodes but gradually thinning as the as-yet-unwritten season progressed. Under 413, the final episode of the season, there was only one single, fluttering card. It read in bold, matter-of-fact Magic Marker ink, "BOOM."

On the other walls were maps of New Mexico and Albuquerque and a detailed schematic, with photos, of Walt's fictional meth superlab located underneath an industrial laundry. Gilligan had originally set the show in Southern California's Inland Empire, the area east of Los Angeles. Thanks to tax incentives, though, production had been moved to Albuquerque, New Mexico. It proved to be a fortuitous change; the tone of the show became inseparable from the south-west's gaping, empty deserts and parking lots, its cul-de-sac communities and domes of vast blue sky. The show was as rooted in its geography as The Sopranos was in New Jersey.

Like The Sopranos, too, it uncannily anticipated a national mood soon to be intensified by current events – in this case the great economic unsettlement of the late 00s, which would leave many previously secure middle-class Americans suddenly feeling like desperate outlaws in their own suburbs. At the same time, the real-world meth epidemic and, across the border, the increasing violence of the Mexican cartels provided a dramatic new backdrop and a whole world into which to expand.

Behind Schnauz was another corkboard, representing episode 405. As the room worked through the episode, each beat or scene would be written on a card and pinned to the board. The last card was always pinned with a little ceremony that meant the episode was locked down. At that point, Gilligan said, it would be so fully imagined and outlined in such detail that, in theory, at least, any of the writers in the room would be able to take over and supervise production.

Right now, the 405 board was blank.

Jesse and Walt busy in the meth lab in Breaking Bad. Photograph: AMC/Everett/Rex

Nearly every discussion in every writers' room, Gilligan explained, boils down to one of two questions: "Where's a character's head at?" and "What happens next?" Ideas v action. Text v subtext. This, as it happened, was a "What happens next?" day, in which the details of a relatively banal plot point need to be worked out.

To borrow a handy acronym, the question was this: WWJD? What will Jesse do? At this point in the series – spoilers follow – the two protagonists, Jesse and Walt, had become dangerously, inextricably tied up with Mexican drug cartels and are under the sway of an ice-cold, manipulative kingpin named Gus Fring, who poses as the upstanding head of a fried chicken franchise. Jesse, distraught from having killed a man for the first time at the end of season three, has been falling apart, hosting a meth-fuelled house party that lasts the span of the three previous episodes. This is simultaneously a threat to Gus, who needs both men, and an opportunity to gain the upper hand.

As Gilligan recapped: "If Walt is dead, Gus has nothing, because Jesse can't cook like Walt. If Jesse's dead, Walt goes berserk and doesn't cook and Gus has nothing. But if he keeps Jesse alive and yet divides Jesse's loyalties in his Machiavellian fashion, then he's really accomplished something."

So Gus instructs his fixer, a flinty, aging hitman named Mike, to take Jesse on as a partner for the day and give him a task that will raise his self-esteem in a way working for Walt doesn't. That still left a bevy of questions. Mainly: "What would that task be?" But also: "How much does Mike know about the plan?"

"This is one of those moments where we know in theory what happens, but we need the specifics. We had a lot of good stuff Friday, but none of it really stuck with me over the weekend," Gilligan said.

With lunchtime approaching, there was a marked increase in shifting in the writers' office chairs. In the centre of the table, there were three categories of items. In ascending order of importance: things to play with (magnets, puzzles, paper clips, a lump of clay) things to write with (stacks of legal pads and index cards, a pretzel jar filled with pens and Sharpies), things to eat (candy and snacks of every description). There were more and more bathroom breaks and a brief conversational detour into quotes from The Big Lebowski. A small faction of the writers took a quick trip downstairs to see how extreme the temperature had become.

Throughout it all, Gilligan kept up a stream of talk about the problem at hand, sometimes as if to himself. "Fuck," he finally said, spinning around in his chair. "Why is this so hard?"

Inevitably, the line between "What happens next?" and "Where's a character's head at?" began to blur. "By the end of the season, it should be that Jesse is torn between two friends, or masters … " Gilligan said, groping toward a breakthrough.

"Just say 'lovers'," said one of the writers.

"No, it's a custody battle! 'I don't know whether I want to live with Mom or Dad!'" Gilligan nearly shouted, grinning.

This instantly rang true. Jesse's relationship with Walt had always been that of a dysfunctional father and son. And the room's energy was suddenly refocused.

"Walt is like, 'He's trying to turn you against me, don't you see?'"

"His house is bigger than mine. Is that the problem?"

Gilligan was laughing: "He's got a PlayStation. All I have is Sega."

Jessie and girlfriend Jane in season two of Breaking Bad. Photograph: AMC/Everett/Rex

The insight did little to overcome the immediate hurdle, but it added yet another thread to the dense psychological warp and weft of the series. "Historically, this has been a medium in which you say more than you show," said Gilligan. "You just didn't have the budgets and scheduling largesse that movies had, so you had to have two people in a room, talking it through." As television budgets increased – along with the size and quality of televisions themselves – that had changed, and Gilligan was intent on taking advantage of the shift. Breaking Bad is by far the most visually stylised show of recent years. It employs and empties the entire filmic bag of tricks – from high-speed time-lapse montages to wide-open landscapes that are more John Ford than anything a revisionist western like Deadwood could ever allow itself.

The signature shot, used at least once per episode, is a fish-eye view up from under or inside some improbable place – a table, a toilet, a bag, a massive chemical boiler. Seen once, it is a cool effect; twice through 10 times, a self-conscious gimmick; 65 times, something approaching a guiding ethic.

This afternoon, it seemed, little storytelling would be taking place – visual, verbal or otherwise. Lunch came and went, with no answer to the Jesse question. "It's the kind of thing where we'll know it when we hear it," Gilligan said with genial resignation. "I just haven't heard it yet." Finally, the staff broke for the day. The discussion would take up another three days before being settled: Jesse would be explicitly instructed to guard the radio knobs in Mike's car while Mike ran errands – not touch the knobs, merely guard them. The detail was duly recorded on an index card and pinned to the bulletin board. At the end of the day, it would be included in a 15-page, single-spaced digest of daily notes. Then it was enshrined in an outline, to be fleshed out in Schnauz's script. That, in turn, was passed around for notes from each of the other writers and Gilligan himself, before being sent back for a revision. Eventually, it would make its way into the crisp white pages of a production draft.

Then the story moved onward: to the tone meeting, the production meeting, the table read. It was pored over by line producers, prop masters, location scouts, production designers, scenic designers, costume designers, directors, assistant directors, second assistant directors, and second second assistant directors – at each step becoming more real, as if emerging from the shimmer of some distant desert horizon. Finally, it was off to New Mexico to be set, for ever, on film.

And then it came to us: by fiber-optic cable, by the internet, by digitally imprinted disc; into our homes, our bedrooms, the phones in our pockets; and we absorbed it, discussed it, argued about it, recapped it, pressed it on our friends. It became one more holy object in the communal sacrament that, thanks to the gods of business, technology, and creativity, TV had become in the early 21st century.

Somewhere along the line, the knobs were dropped. The task ended up as nothing more complicated than riding shotgun while picking up hidden packages of money in a series of remote locations. Unfolding as a montage, it took up 82 seconds of screen time.

This is an edited extract from Difficult Men: From The Sopranos and The Wire to Mad Men and Breaking Bad by Brett Martin, published by Faber and Faber at £14.99 on 3 October. Buy it for £11.99 at guardianbookshop.co.uk