Much has been made of the way the writers of Breaking Bad — which debuted to modest ratings on January 20, 2008, before growing into one of the defining shows of its era — wrote themselves into corners, before improvising their way out.

They’d often get their protagonist, meth-cooking schoolteacher Walter White (played brilliantly by Bryan Cranston), into a seemingly impossible-to-resolve dilemma, and then reveal that he was far more devious than viewers had ever expected. It made him a compelling character to watch, even when he was growing more and more amoral, but it was also a lot of work for the show’s writers, who had to make his schemes seem completely unexpected yet also completely inevitable once you knew what they were. (Alan Sepinwall talked with Breaking Bad creator Vince Gilligan about this very writing process.)

And almost as much has been made of how Breaking Bad, despite being the heavily serialized journey of a man from mild-mannered teacher to crime boss, worked beautifully on an episode-to-episode level. Today’s serialized dramas seem to have learned all the wrong lessons from it, in fact, believing that knowing the big picture is more important than sweating the details.

Yet Breaking Bad wouldn’t have worked had it not found a way to perfectly balance those smaller, often improvised strokes against a big picture that felt perfectly plotted when you stepped back and took a look at it. How did it mesh these two seemingly contradictory qualities?

The answer is that Vince Gilligan and his writers had a plan — just in the broadest of strokes (famously expressed by Gilligan as “Mr. Chips turns into Scarface”). And they were able to realize that plan because they had an almost airtight understanding of story structure and how it works at both micro and macro levels. So let’s talk about William Shakespeare.

Five-act structure underlies both Shakespeare’s plays and many of your favorite TV shows

Most of the time when we talk about cinematic story structure, we’re talking about the three-act structure with a beginning, middle, and end, which looks something like this:

Many screenwriting students are taught three-act structure in this fashion — have a character climb a tree, throw rocks at them, then get them down from the tree. (This advice, popularized by screenwriting guru Syd Field, is commonly attributed to Mark Twain, though no one knows who actually said it first.)

That works well in movies because movies have finite running times. On a long-running, serialized TV show, structuring three acts becomes much tougher, because the second act tends to stretch on forever and the writers run out of rocks to throw at the characters. That’s why many of the best TV shows use a five-act structure — or that thing you learned about in high school when you were reading Romeo and Juliet for the first time.

The main difference here is time. You’ll notice the shape is roughly the same, but the five-act structure gives both the buildup to and fall from the climax whole acts to breathe. Instead of getting stuck in a never-ending second act, much of the story is pushed to the fourth act, or the fallout from the big moment. And on TV, time is everything:

The five acts consist of the following, which I have paired with how each act perfectly corresponds to each of Breaking Bad’s five seasons:

Act 1: Something happens to spark the story into motion, and the characters begin making choices that will set everything else spinning along. (In Breaking Bad season one, Walter begins cooking meth and realizes he kind of likes it.)

Something happens to spark the story into motion, and the characters begin making choices that will set everything else spinning along. (In Breaking Bad season one, Walter begins cooking meth and realizes he kind of likes it.) Act 2: The characters still have a chance to escape their fates, but something in their psyches keeps driving them forward. (In Breaking Bad season two, Walter delves deeper and deeper into the Albuquerque underworld, meeting figures like Saul Goodman and Gus Fring for the first time. The season ends with a “warning from God,” in the form of a plane crash.)

The characters still have a chance to escape their fates, but something in their psyches keeps driving them forward. (In Breaking Bad season two, Walter delves deeper and deeper into the Albuquerque underworld, meeting figures like Saul Goodman and Gus Fring for the first time. The season ends with a “warning from God,” in the form of a plane crash.) Act 3: Featuring the “climax,” this is where everything shifts. Something happens to flip everything on its ear, and the story reaches a point where the characters cannot escape what’s coming. (In Breaking Bad season three, Walter leaves the drug business behind for a while, but ultimately decides to join Gus’s empire. I would pinpoint the show’s “climax” as the controversial episode “Fly,” in which Walter has the chance to come clean to his closest colleague and decides not to.)

Featuring the “climax,” this is where everything shifts. Something happens to flip everything on its ear, and the story reaches a point where the characters cannot escape what’s coming. (In Breaking Bad season three, Walter leaves the drug business behind for a while, but ultimately decides to join Gus’s empire. I would pinpoint the show’s “climax” as the controversial episode “Fly,” in which Walter has the chance to come clean to his closest colleague and decides not to.) Act 4: The characters, trapped by fate but not yet cognizant of it, are sucked toward the endgame. In a tragedy, this is often when the body count begins to mount (or the audience can see this coming). (In Breaking Bad season four, the war between Gus and Walter dominates everything that happens.)

The characters, trapped by fate but not yet cognizant of it, are sucked toward the endgame. In a tragedy, this is often when the body count begins to mount (or the audience can see this coming). (In Breaking Bad season four, the war between Gus and Walter dominates everything that happens.) Act 5: Everything ends, often in blood and horror. There is some quiet musing on what it all means. A few characters escape with their lives, but even they will likely have long years of therapy ahead of them. (In Breaking Bad season five, Walter takes over the Albuquerque drug world but finds himself pairing up with even more unsavory characters. Eventually, just about everybody dies or has their life utterly ruined.)

The five-act structure can be used for anything — Shakespeare wrote both tragedies and comedies, after all — but modern writers seem to use it for tragic dramas more often than not. On television alone, The Sopranos and The Americans (about which I wrote much more as a five-act drama here) have both used a rough five-act structure to tell their stories, and more and more shows seem dedicated to this sort of loose organization of their stories, especially because most viewers intuitively feel this structure in their guts. It gives the story a feeling of inevitability while leaving the writers plenty of room to improvise.

Related This Breaking Bad technique has influenced everything from Walking Dead to This Is Us

Even better, the five-act structure loosely mirrors how TV episodes are structured. Traditionally, hour-long dramas had to account for four commercial breaks, which split an episode of TV into what were dubbed “five acts.” Each act needed to end on a moment big enough to keep the audience watching through the commercials. And thus, the most successful TV shows used very rough forms of five-act structure to keep viewers watching.

That’s changed now, as networks have added more and more commercial breaks, leading to what’s essentially a six-act structure. But even here, Breaking Bad pointed the way forward, using its “teaser” (the section that plays before the opening titles) as a kind of disconnected prologue that told its own mini story, thus allowing the rest of the episode to unspool as a more traditional story. And Breaking Bad’s teasers have become one of the most influential things about it.

The five-act structure let Breaking Bad know where it was going without having to know where it was going

To be sure, this kind of structure can end up hampering a story in the latter part of its run, when things start to feel too inevitable (something I would argue hurt some of Breaking Bad’s later episodes). And it tends to work better with shows that have a singular protagonist (or only a couple of protagonists) than shows with large ensembles. Mad Men, for instance, didn’t really work as a five-act show on the macro level, but that was fine because it was charting the growth of a whole bunch of disparate characters.

But the five-act structure unquestionably helped give Breaking Bad the tragic weight it wouldn’t have managed without that sort of rigor. The horror and power of “Ozymandias,” the show’s third-from-last episode and probably its finest hour, wouldn’t have worked without having all of that careful buildup, but it also worked because on some level, we’re trained to expect these sorts of late-in-story revelations to have that much horror and power.

Gilligan and his writers, knowing exactly how story structures work, could use that to their advantage, right down to revealing Walter’s crimes to everybody late in the run, but not so late that he didn’t have to feel their ramifications.

And the five-act structure also meant that the show’s choice to make nearly everything (including that plane crash!) stem directly from Walter’s choice to start cooking meth didn’t feel as forced as it could have. Again, we’re used to stories like this hinging, sometimes improbably, on the choices of the protagonist, and it’s not hard to see Walter as someone like Hamlet or Richard III, consumed by his own demons as much as he sets demons in motion.

It’s clear that everybody in television wants to make the next Breaking Bad. When I asked a showrunner recently what she was tired of seeing in sample scripts sent to her by young writers (who often will write what’s called a “spec pilot” for a show of their own devising), she pointed out just how many drama pilots she read that were beat-for-beat recreations of the Breaking Bad pilot, right down to the opening that picks up in the middle of the story.

But what too many writers miss about Breaking Bad is that its big story, which feels so carefully planned, was only planned in the loosest of senses. Instead, the series works because of how well it understood what is needed to make a story successful. That pitch-perfect comprehension of the skeleton that underlies a great story meant the show’s writers could feel free to detach from worrying about the big picture to sweat the small stuff and come up with some of the most memorable TV moments ever.

Breaking Bad is streaming in its entirety on Netflix. If you haven’t watched it by now and somehow made it through this entire article, sorry for the spoilers.