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!