When David Letterman walks off the stage of the Ed Sullivan Theater for the last time, he’ll take more than 4,000 hours of the “Late Show” with him. And a couple thousand hours of “The Late Late Show.”

The retiring host is the founder of Worldwide Pants Inc., which produced both programs, as well as a handful of sitcoms. Thanks to an unusual deal Letterman signed when he joined CBS Corp. in 1993, his company owns a library of footage that includes early Jerry Seinfeld stand-up, guest appearances by Bill Murray and Madonna and a piece of Joaquin Phoenix performance art. (In which the actor, wearing an untamed beard, says he’s quitting the profession to become a hip-hop musician.)

Now the 68-year-old Letterman, whose final show is Wednesday, has to decide what to do with reel upon reel of Top 10 Lists, stupid pet tricks and other moments of late-night history.

“There’s a lot of talk about the library, which is extremely valuable if handled correctly,” said Rob Burnett, Worldwide Pants’ chief executive officer and executive producer of the “Late Show.” Some of it hasn’t been digitized yet, and only a fraction has made its way to YouTube, he said. “In today’s world there are a lot of ways to monetize something with that volume and quality.”

“Late Show with David Letterman” predates YouTube, Snapchat, Facebook and Twitter, which have reshaped late-night TV. Letterman’s peers, Jimmy Fallon and Jimmy Kimmel, host programs crafted for the social media generation, with skits and nuggets that people share online the following day.

“The Web has changed how people interact with archival footage,” said Jeffrey P. Jones, director of the Peabody Awards at the University of Georgia in Athens. “Whether Worldwide Pants can translate that into some currency on the web is really yet to be seen.”

Passed Over

Letterman is in a position to find out thanks to a career tragedy -- being passed over by NBC to replace Johnny Carson on “The Tonight Show.” CBS then pursued him, awarding him a deal with no modern equivalent. Letterman would own his late-night show, with the right to produce and own a second show, “The Late Late Show.” (Carson, too, owned his own show.)

For 22 years, CBS has given Letterman a lump sum, which he uses to pay himself, his staff and produce the “Late Show.” Any leftover cash went to Worldwide Pants; the company invested most of it in the show. CBS makes money selling advertising, charging as much as $30,000 for a 30-second spot.

The network isn’t likely to make that kind of arrangement again. It owns both “Late Show with Stephen Colbert,” which begins in September, and “The Late Late Show,” hosted by James Corden.