As happens to so many of us, I was asked to write a sitcom for Croatian television. I’m an American ex-pat living in Slovenia, and I know next to nothing about Croatia, besides the fact that it’s Slovenia’s southern neighbor, a fellow ex-Yugoslav republic, and that the language resembles Slovene except with a lot more “js” in it. I am a writer of books and articles, and I used to write a lot of plays, but I’ve never written for television. So I immediately said, “Sure, of course I can do that,” before rushing off to Google “How to write a sitcom.”

In addition to much Googling, I spent a good deal of time watching sitcoms. I was after tips on how they are constructed, and watched actively, looking to crack open their laugh-tracked shiny exterior to get at the goopy mechanism within, to see how they functioned.  What I found out surprised me, and changed the way that I watch television.

From The Simpsons to Seinfeld, from Everybody Loves Raymond to Everybody Hates Chris, from Taxi to Arrested Development to Parks & Recreation, there is a highly-specific, minute-by-minute recipe used to write the vast majority of sitcoms out there. And once you know the formula, it makes it much easier to write them, and much harder to watch them without seeing that formula—the “sitcom code”—everywhere you look.

My giddy-panicked Googling actually produced fruitful results. With little idea as to where I should begin, I turned to the confidence-inspiring blog, Wise Sloth (whose author, like me, has no TV writing experience), which provided a 15-page breakdown of sitcom formats that I used as a point of departure for my own study. And by study, I mean hopping into my pajamas, cuddling up to my Peruvian Hairless, and watching TV with a notebook in hand. Talib Visram recently wrote in The Atlantic about his experience counting jokes per minute in popular TV shows. My approach was more deconstructionist, and directly applicable to my new gig. I had to figure out how such shows were built, and fast.

Fortunately, the answer presented itself very quickly.

First of all, word-processing programs often come with screenwriting templates. FinalDraft, the most popular software for those penning scripts, even has a Sitcom Template, which of course makes life much easier. But as for how to construct an episode, various bloggers, from the Wise Sloth to helpful folks at the BBC, noted a basic structure that I immediately recognized in every sitcom episode I tested. This structure is so formulaic that you’d think it would suck the fun out of writing and watching such shows, but it does nothing of the sort.  While knowing the code it changes the way I watch TV, it only increases my admiration for the good writers who do so much within relatively strict confines.

To demonstrate how this formula works, I’ve chosen an episode of a favorite show, somewhat at random, because it ideally exemplifies the template: episode 4 of season 1 of Parks & Recreation.

The Sitcom Code breaks down what needs to happen in each episode, by the minute. As Dan Richter of Demand Media notes, “Sitcoms, minus commercials, are typically 22 minutes long [with] a script of 25-40 pages. Every sitcom episode has a main plot (story A), as well as one or two subplots (stories B and C).”  There are three main acts, divided by two commercial breaks (in most American TV), with 3-5 scenes per act. One of the distinguishing characteristics of sitcoms, as opposed to other forms of television, is that the main protagonist(s) barely change from one episode to the next, let alone from season to season (Maggie Simpson has been sucking on a pacifier for nearly thirty years). Therefore whatever happens in the episode, the situation must end largely where it began. The Wise Sloth points out that 22 minutes is “not even really time enough to tell a full story.  The whole story has to be on fast-forward,” so simplification is key.

Poet Philip Larkin described all plots as “a beginning, a muddle, and an end,” which is as good a description as any. Each episode begins with the protagonist stating a goal or problem that must be solved, and which we understand will be solved by the end of the episode. If the problem is solved too quickly, then the episode won’t stretch out to 22 minutes, so the first attempt at reaching the goal or solving the problem must fail (“the muddle”), requiring a new approach, before the episode ends and the protagonist either does, or does not, achieve what they set out to do.  The goal might be Homer trying to make a fortune by selling recycled grease in The Simpsons, or Job Bluth setting out to sabotage the family’s banana stand in Arrested Development, or the Seinfeld crew looking for where they parked in a vast lot.  Another hallmark of sitcoms is that the protagonists frequently fail, and we often want them to, because we do not want our favorite characters to change too much.  If Leslie Knope ever left Pawnee for a career as a DC politician, we would be distraught.  If Kramer got married and moved to the suburbs—whoa, now!

When writers sit around and prepare a new episode, many literally map out what will happen, minute-by-minute, in the main storyline and sub-storylines, filling in jokes later.  Let’s see how this played out in the Parks & Recreation episode, “Boys' Club.”

The Teaser (Minutes 1-3)

A short, introductory sketch that often runs before the credits.  It’s little more than a set-up, delivery and reaction: a single joke.  It introduces the protagonist and shows some aspect of their personality (for viewers new to the show), and ideally it introduces viewers to the main obstacle to be overcome in the episode. But as often as not, it is simply a quick joke to get the ball rolling.

Leslie Knope and her assistant, Tom Haverford, arrive at a park where they’re checking on reports that kids are having fights with dog poo. The rumors are confirmed. Noble Tom hides in the car, while principled Leslie first tries to confront the kids, is fired upon with a barrage of dog poo, and then fires back, admitting that this actually is a lot of fun. We see Leslie’s role as a local government authority, and her strong (but porous) moral stance.

The Trouble (Minutes 3-8)

We meet the protagonist(s) and see that they’re just where we left them last episode, but a new problem or goal has come to their attention, which forms the main plot (Story A) of the episode. A plan must be made as to how the goal is to be achieved, or the problem overcome. Around the 6th minute we might be introduced to a subplot (Story B). Subplots must be even briefer than the main plots, and feature one of the minor or secondary characters. It’s great if the subplot can somehow link to the ultimate conclusion of the main plot, but this is not necessary. Think of each subplot as a main plot in miniature, likewise with a beginning, a muddle, and the end.

Trouble arrives in the form of a gift basket of wine and cheese that Leslie thinks is a bribery attempt from a local firm. She reprimands her colleagues for wanting to dive into the basket’s goodies. They complain that she’s a goody-two-shoes, and we see her as self-righteous—a beautiful setup for a fall. We also see the Old Boys Club: every Tuesday some guys in another government department drink beers in the courtyard, including Mark, whom Leslie has a crush on.  She grabs her friend Ann and plans to “shatter the glass ceiling” by infiltrating this men’s club. They’re welcomed immediately and join the fun, but quickly run out of beer. Trying to keep the party rolling and impress Mark, Leslie breaks open the gift basket that she had previously sequestered and opens the bottles of wine.

The Muddle (Minutes 8-13)

The plan drawn up a few minutes ago to tackle the main plot is put into action, but it can’t work or the episode would be over already. There must be another obstacle, a spanner in the works that requires an alternative plan or some amusing delay to the success of the initial strategy. As the Wise Sloth writes, the characters must “confront these obstacles according to their own personal style,” meaning that Leslie will approach the problem with her boundless enthusiasm for government and abiding by rules that the little girl inside her sometimes wants to break.  With subplots in play, minutes 8-9 establish where we left off with Story A. Minutes 9-12 provide the middle muddle of Story B (the secondary character overcomes a minor obstacle toward their goal), and then minutes 12-13 return to Story A, and see the main plan diverted.

Distraught at having broken the code of ethics that she so firmly sought to uphold, Leslie confesses to her colleagues. We are then introduced to Story B, in which a secondary character, Andy, despite his leg being in a cast and his slovenly personality, plots to secretly surprise girlfriend Ann by cleaning the house, and himself, while she’s at work. Back at the Parks & Rec office, Leslie “whistle blows herself” and confesses to her boss, Ron, who merely tells her not to make a big deal of the situation. This could be the end of the show, but it is coming too soon. Where’s that spanner? Back at Story B, we see Andy hobbling along and cleaning the house, then throwing the garbage in the neighboring pit that has been a recurrent theme of past episodes. And then there’s the spanner: underage intern April is bored at work and films herself drinking leftover gift basket wine, then puts the video on the official, Leslie-sanctioned website of the aforementioned pit.  Ron confronts Leslie, who is now called before the disciplinary committee.

The Triumph/Failure (Minutes 13-18)

By this time, the protagonist is getting desperate and the stakes are high—they’ve already tried once and failed. They turn to a last resort, put it into play, and it works…or it doesn’t. Remember that failure is frequent and fine in the world of sitcoms, unlike feature films and dramas. Failure is humorous rather than frustrating, because again we don’t want our characters to change. Minutes 13-15 re-establish the action of Story A, but pause before the payoff of whether or not the backup plan will work. Minutes 15-17 conclude Story B: the secondary character either does, or does not, accomplish what they set out to do, and this may, or may not affect the outcome of Story A. Minutes 17-18 show whether the protagonists succeeds or fails in Story A.

Ron sits beside Leslie at the disciplinary committee hearing.  Leslie reads out a passionate confession. Meanwhile, back at Story B, Andy cleans himself in a kiddie pool, but a neighbor steals his boom box. Naked and soapy, he gives chase.  Returning the Story A, Ron defends Leslie against the committee. His anti-government, anarchic stance (despite working for the government) gets her out of a jam. His intervention means that Leslie will only receive a letter in her file, and will not be fired. Leslie confesses to Ann that she opened the gift basket not just to “shatter the glass ceiling” and allow women into a boy’s club, but because she has a crush on Mark. Story A is resolved, as is Story B. Ann returns home to a clean house and clean Andy, who has succeeded in his goal, despite the mini-muddle of the neighbor stealing his boom box.  He announces to us that he will “get gently laid tonight.”

The Kicker (Minutes 19-21)

Like the teaser intro segment before the credits, there is usually an “outro” (sometimes while the credits are rolling), which shows the protagonist in the aftermath of that episode’s action. We find it comforting to see that nothing has really changed, and life has reset, back to where it started and primed for the next episode. It might end with a nice punchline at the end that brings back a joke from earlier in the episode.

In “The Old Boys Club,” the kicker is not a joke but a propulsion into the next episode, fleshing out the budding romance between Mark and Leslie. Mark brings Leslie a beer at her office, after hours, saying “welcome to the team.” She is in the boy’s club, and Mark may reciprocate her feelings for him.  Roll the credits.

This deconstructionist approach to sitcoms was truly helpful when it came time to write my own, as I had minute-by-minute slots to fill and a strong idea of this endlessly successful and recycled series of plot arcs. But I still had to write the darn thing. The Croatian public were waiting.

Next time you settle in to watch a sitcom, keep this code in mind, and an eye on your stopwatch. You’ll be amazed at how tight and to-the-minute the formula is, yet marvel at the variety that TV writers conjure within this straitjacket literary form.  Now, I better start Googling “what Croatians find funny…”