There’s a reason Silicon Valley worked from the moment it premiered on HBO in 2014: It was only about the pursuit of tech greatness and never ever about icky stuff like office romances or boring backstories.
The critically acclaimed comedy, which just aired its finale Sunday night, centers on programmer Richard Hendricks (Emmy nominee Thomas Middleditch), who creates an app with a game-changing data compression algorithm and founds the startup company Pied Piper with an eccentric group of coders. For Richard, Gilfoyle (Martin Starr), Dinesh (Kumail Nanjiani), Jared (Zach Woods), and Monica (Amanda Crew)—and tangentially Big Head (Josh Brener), Jian Yang (Jimmy O. Yang) and, yes, Erlich (T.J. Miller)—nothing mattered more than creating something indelible and good, away from the predatory glare of Big Tech. And they did. Until they didn’t. And they did again. Until they didn’t. (And so on.)
A week before the finale aired, Fortune sat down with series cocreator Mike Judge, who based Silicon Valley loosely on his own experience as an engineer in the 1980s, and executive producer Alec Berg, who wrote, directed, and appears in the finale as a documentary filmmaker recording Pied Piper’s epic flameout 10 years after the events the episode portrays. Inside their offices on the Sony lot in Culver City, Calif., Judge and Berg revealed what had been their biggest concerns and aspirations for the finale, what they learned from each other over the past six seasons, how they landed Silicon Valley super-fan (and Microsoft founder) Bill Gates for a cameo, and how the series might be the ultimate underdog morality tale.
This conversation has been edited and condensed for clarity.
You’ve both worked on series finales before: Seinfeld for you, Alec, and Mike, King of the Hill and Beavis and Butt-Head. What was distinctly challenging about crafting the ending to Silicon Valley?
Alec Berg: We’d lived with one big idea the last couple of seasons; that the show was, in pretentious terms, about the idea that Richard invented fire. So what does he do with it? Protect it? Does he owe a debt of service to it? Can he sell it? Is he responsible if something bad is done with it?
Essentially what is the—to borrow your word from this season—“tethical” fallout from his technology?
Berg: Yes. We decided it wasn’t right for him to monetize. It would do more good if he set it free, so instead he’d open-source it. We played with that for a few years.
Mike Judge: Then we heard about breaking encryption [something a network teaches itself how to do, essentially writing its own code]. Then it was, “Oh man, that’s the ending.”
So all of Richard’s work over the last six years is essentially moot. What’s the takeaway for the audience?
Berg: It’s about asking the question: Is the point of technology to push, serve, or enslave humanity? For example, take the origin of the QWERTY keyboard. The reason it’s arranged that way is, when they made the first typewriters, if you typed too fast, the mechanism would jam. So they arranged the keyboard to be harder to use.
Judge: It’s deliberately engineered to make you type slower.
Berg: They knew that humans, if left to their own devices, would jam the technology. That explicit theme ultimately fell out of the finale, but the idea that inventing things may not always not be good for us is the takeaway.
And these are ever-more timely themes considering what’s happening with political ads and Facebook.
Berg: Yes. Years ago we met Andrew Mason, who founded Groupon. He was very humble and somewhat embarrassed about it because Groupon actually started as a way of organizing people to boycott companies as social protest.
Judge: He was in a punk band. [Laughs]
Berg: A total social activist. Then he thought, “What if we organized people en masse to negotiate better deals? Rather than stopping commerce, what if we flipped it?” And within a matter of months…
Judge: He was a guy selling coupons. [Laughs]
Berg: It was the fastest-growing company in the history of the world. But he also talked a lot about, Will we look back at things like Twitter as fundamentally horrible moments in society?
Aren’t we at that point now?
Berg: Technically, no. There is still no scientific metric to measure Twitter’s damage. We have anxiety studies, but that’s social science, not physical science. It’s like smoking and cancer. It wasn’t proven until internal company documents said, “We know this is happening, and we need to hide it.”
Judge: “May cause spikes in anxiety!”
Were there series finales you enjoyed as fans and thought, “Okay, if we can go out like that, we’ll be happy?”
Judge: I’m generally not a fan of finales. [Laughs] I loved The Mary Tyler Moore Show and didn’t like that finale. Same with The Bob Newhart Show. When I’ve done it myself, with King of the Hill, I thought it was good, but because animation takes nine months, we had to recut it, and it turned into this weird mushy ending. I also wasn’t crazy about Beavis and Butt-Head’s. [Laughs] But I’m really happy with this one. Alec killed it. It’s dramatic and emotional.
Berg: I had a front-row seat to the Seinfeld finale, which I loved. But what people didn’t like was they’d had a love and reverence for these characters, and the finale said, “No, these are petty people.”
And they were petty all along, but we didn’t want to see that.
Berg: Right. So the end of Silicon Valley was about: Okay, what have these characters earned? What is happiness for them? The most interesting case for me was Gavin Belson. He was always the enemy. So how do we punish and defeat him? Then it was, “Wait, do we actually hate Gavin? Maybe we like him?” Ultimately his punishment is his own delusion. The idea that he’d have to deal with a nattering writing partner was perfect; a low-level, stabbing pain.
And what’s the lesson for Richard? That being a success is inherently incompatible with being a good person?
Berg: He isn’t cut out to be a brutal taskmaster or CEO. He’s an artist. That’s always been the clash in the show. If he were as ruthless as other CEOs, he’d be fine, but he always had a sense of moral justice and propriety.
Judge: But he did get to save the world. And that drama of not being able to tell anyone about it was very satisfying.
Berg: Failing publicly and acting like you’re a pariah while secretly knowing the truth!
Judge: There are probably people who will wonder, “Couldn’t Richard just get rich and be happy already?”
Berg: “Can’t they just be successful for a couple of episodes?” And we did try that. We’d sit down and try to write those story lines. But it wasn’t nearly as much fun to write when they weren’t struggling.
Who was your favorite character to write for?
Judge: Early on it was Peter Gregory [played by the late actor Christopher Evan Welch]. Then it was Gilfoyle. Then Zach started doing amazing improv for Jared, including a line where he hinted at his dark foster-care past. We started writing to that, and it evolved to that amazing scene this season when he meets his birth parents, who reject him. It was a super-sad scene. After rehearsals Zach said, “God, I really feel emotionally beaten.”
What are some of the most memorable notes you received from HBO over the years?
Judge: [EVP of programming] Amy Gravitt is a great collaborator. I’ve even asked her to come to final mixes because I trusted her opinion so much. But I remember they wanted the stripper in episode two to be naked. Like, “Come on, it’s HBO!” But I didn’t want that, because that scene was about the total opposite: Our guys want to leave the room when the stripper arrives.
Berg: We wanted to use a Green Day song for the pilot credits, but it was very expensive. HBO asked us to find another song. And we did, and it was fine. Then we were in the final sound mix, and the replacement song comes on.
Judge: And Amy had this disappointed look. I thought, “Oh, God, she hates the episode.” And she says, “I like Green Day better. Let me make a call.”
Berg: And they approved it.
Judge: It cost like $30,000 or $40,000. [Laughs]
Did Amy, or you for that matter, ever worry about the density of the tech content? That it was so accurate and insidery, it might alienate viewers?
Berg: Yeah. But it’s like watching a medical show. We don’t understand that stuff either. But if you attach emotion to all that jibber-jabber, it works.
Judge: We’ve also been lucky to have great tech consultants, led by Jonathan Dotan. In the second-to-last episode this season, there’s a scene where Richard is unhinged about what he did with Gilfoyle’s A.I. I had to cut a ton of it, but Jonathan emailed and said, “You have to put ‘Fuck gradient descent!’ back in.” I was like, “Okay!”
So generally your consultants would read the scripts, and they come back with notes and edits?
Judge: Yes, and we’d show them rough cuts and more finalized cuts.
Berg: But at the beginning it was more open. “So…what would these guys actually do all day?” [Laughs]
Judge: I visited some startups when I wrote the pilot. And I used to program myself, but it was so different back then. Alec and I were like, “Great. Neither one of us knows what these characters are actually doing.” [Laughs]
Berg: Each season we’d do research in Seattle, the Bay Area, and Palo Alto and ask, “What’s the latest thing?” The cryptocurrency thing last season, that was an instance where every person we talked to had said: “Crypto, crypto, crypto.” Then as we were doing it, Bitcoin took off. I remember listening to the radio one morning. “Here’s the traffic, the weather, and Bitcoin is up to whatever.” I’m like, “Whoa.”
Judge: When that episode came out, my friend Willie D from the [rap group] Geto Boys was like, “Yeah, I just made $16,000 off cryptocurrency.” [Laughs]
Berg: We’ve put in a lot of real-world stuff without having to change a thing. Like Gabe and the wearable chair this season—we saw that in an office once and said, “That’s so obnoxious, it has to be in the show.” And in the pilot, Peter Gregory’s narrow car.
Judge: I think [production designer] Richard Toyon suggested it. It was some crazy electric car that really existed, but lot of people thought we’d made it up.
Berg: And it got one of the biggest laughs. That’s the great thing about writing a show about this business. So much is fucking ridiculous.
Bill Gates had long been a fan of the show, and you finally got him for a cameo in the finale. How did you pull that off?
Berg: We’d met and spent an hour with him in 2017. We asked, “If you had advice for Richard, what would it be?” He said, “If you get petitioned by a foreign government to explain your business to them, you should go in person.” [Laughs] We’d talked about putting him in the Senate hearings episode at the beginning of season six.
Judge: But this was better. If you get him, you might as well save him for the end.
Berg: He was so great and incredibly prepared. We set up for two hours at his offices [in Kirkland, Wash.]. They said, “He’ll arrive in one hour and 42 minutes.” He walked in exactly when they said. “You’ll have 15 minutes with him.” He gave us about 20. “Okay, we have to take him now.” It’s funny, we never really had a big discussion about that scene; only just that it feel very real. That’s been our approach overall. It’s also made the show 10 times harder to write. There’s that saying: “Comedy thrives in a confined space.”
Judge: The challenge of being confined to writing about introverted people who sit and program all day forces you to come up with creative solutions. [Laughs]
Berg: And tone, too. This show is about the comedy of pause, silence, and awkwardness. Thomas’s awkwardness specifically.
You didn’t know each other before working on the show. What have each of you learned from the other?
Berg: Mike is a musician and has such a great ear. It’s how he casts actors. It’s easy to wear your writer hat a little too much like, “I wrote this character, and he’s this.” But Mike has an amazing ability to listen and go, “That sounds good with that. That sounds good with that,” instead of imposing his will. I’ve learned a lot from that approach and use it now with Bill Hader on Barry. It’s two idiots at the piano hitting notes going, “Is it this? No. Is it this? No.”
Judge: Alec has the best story brain ever. He actually solved one of the biggest problems I had with the first episode.
Berg: After [current HBO programming president] Casey Bloys and Amy Gravitt developed the project for HBO, Sue Naegle [then president of HBO entertainment ] called me and said, “We have this Mike Judge pilot. Can you take a look?” I was already a huge fan.
Judge: The fun of capturing this world for me was seeing introverted people suddenly get rich. But we didn’t want to explore that with our main characters. So Alec said, “Why not open with a big Silicon Valley party scene so when Richard says no to the $10 million offer, we relate more to the life he’s turning down?” The clouds parted, and I was like, “God, that’s great.” I love how Alec is always willing to admit when things aren’t working, and how important it is to dig into the real world.
Berg: I got that from Seinfeld. People would pitch story ideas; five were “Here’s a zany thing Kramer could do!” and one was totally off-the-wall, like when he finds the discarded Merv Griffin set in a dumpster. Then the writer would inevitably say, “That actually happened to me.”
You could somehow sense when a gag was rooted in reality.
Berg: One hundred percent. Those are the ideas that, if you sat in a room for a thousand years, you’d still never think of them.
Is there a joke from Silicon Valley that you feel best represents the way you wrote the show?
Berg: A lot of people love the “jerk-off equation” from the season one finale. There was a hole in that story, and we needed a very funny way for Richard to get inspired.
Judge: Some funny analog to a mathematical thing.
Berg: One writer had talked about—completely unrelated—how he and his friends had a running joke about how you could jerk off four guys at once if they stood tip to tip. It was my Beautiful Mind moment. “Yes that’s it!” [Laughs] Actually, the rats in the finale— that idea came late and in a similar way. We talked to [consultant] Todd Silverstein about how the guys could fail in the finale. Maybe they shut down the network, and phones start emitting a weird noise? Then Todd told us he’d lived in an apartment where the person downstairs had a sonic pest repellent. It drove rats and bugs crazy, and they ran into his apartment. Then [writer] Sarah Walker goes, “Wait! Rats and Pied Piper!” And we were like, “Oh, my God.”
And here people thought you’d been sitting on that joke for six years.
Judge: Yes, we decided to name the company Pied Piper because we knew, six years later, we’d being doing a scene with rats. [Laughs]
The finale answers a lot of questions, and yet leaves us with one great, lingering mystery: Did Jian Yang kill Erlich Bachman? So, did he?
Berg: There were more definitive versions of it that felt too ghoulish. I think it’s funnier to be coy, and let the audience fill in the blanks. By the way, Thomas improvised what’s maybe my favorite line in the finale: When he finds out that Jian Yang is dead, he turns to the camera crew and says: “Um, okay, he’s dead. What do we do?” [Laughs]
Judge: Totally what an engineer-type would say. “I don’t understand emotions.”
Berg: I feel like we’ve always deferred to the actors for those moments. Even when we were running late, if they asked, “Hey, can I just try one thing?” We’d say yes because it was likely going to end up on-screen.
Judge: They saved a lot of scenes that maybe weren’t great to begin with. It also helped that the actors always understood their characters; we never had to fight them to get what was best for the show. They were their own unique versions of underdogs. Who knew we could find that many different flavors of nerd?
More must-read stories from Fortune:
—The Mandalorian composer Ludwig Göransson on crafting a new Star Wars soundscape
—The Aeronauts director on how he pulled off the high-flying adventure film
—Knives Out: Rian Johnson and composer Nathan Johnson discuss their cousinly collaboration
—Alan Cumming on taking career risks in his 50s and “spinning a lot of plates”
—Honey Boy director Alma Har’el carves out space for female filmmakers
Follow Fortune on Flipboard to stay up-to-date on the latest news and analysis.