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.

Loving Raymond

Worldwide Pants has produced several other shows, including “Ed” and “Bonnie,” the most successful being “Everybody Loves Raymond,” which it co-owns with HBO and CBS. The show was once one of the 10 most-watched TV series in the U.S. It’s been licensed again and again; a 2005 deal with Time Warner Inc.’s TBS netted around $650,000 an episode -- which added up, considering there are 210 episodes.

But the owners have already extracted most of the value from the hit, as shows command less money the longer they’re in syndication. “Raymond” has ceded its place in culture to “The Big Bang Theory” and “The Office,” both of which TBS also licensed. And Worldwide Pants hasn’t been as active in producing sitcoms recently, with Burnett and Letterman focusing instead on the “Late Show.”

It’s easier to map out how much revenue a sitcom will generate in syndication than a talk show that has few predecessors and isn’t popular overseas.

Active Half-Life

“The Letterman show doesn’t have the same kind of value that syndicated hits have,” said Seth Willenson, a former executive at RCA and New Line Cinema Corp. “There’s a very active half-life on variety shows. Clips would generate more revenue, but I don’t think it would be revolutionary.”

The volume and breadth of those clips will make the library valuable, Burnett said. It’s not justLetterman riffing on current events, but years of stand-up and other cultural memorabilia. They have a future on YouTube or Yahoo, in documentaries and any number of other landing spots, he said.

Burnett, who started working with Letterman 29 years ago as an intern, said he isn’t interested in overseeing a library business. The former head writer of the “Late Show” is editing a movie he wrote, produced and directed, an adaptation of the novel “The Revised Fundamentals of Caregiving,” which stars Paul Rudd and Selena Gomez.

He wants to spend more time on his own creative endeavors and less time managing other people’s projects, he said. Letterman has said he wants to let his 11-year-old son dictate his schedule.

The company may need to hire someone, Burnett said.

“I honestly don’t know what the future of Worldwide Pants will be,” Burnett said. “We’ve built a brand here. There is value. Ultimately it will be to Dave to decide what he wants to do with that.”