During his monologue, Letterman joked that the Arizona senator reminded him of "the guy at the hardware store who makes the keys" and "the guy who can't stop talking about how well his tomatoes are doing."
After Letterman added that McCain looked like "the guy who points out the spots they missed at the car wash," the senator appeared on stage.
"You think that stuff's pretty funny, don't you?" McCain asked, then added: "Well, you look like a guy whose laptop would be seized by the authorities."
The candidate also likened Letterman to the manager of a creepy motel, the guy who enjoys watching his swim trunks inflate in a hot tub and the guy about whom neighbors later say, "He mostly kept to himself."
Later in the show, the two discussed more serious issues, including the national credit crisis, Iraqi casualties, the U.S. prison at Guantanamo Bay, Cuba, Bear Stearns and accusations that McCain's not a true conservative Republican.
"I think maybe some people think that you ought to have exactly the same position they have on every issue," McCain said.
The two Democratic candidates have also appeared on the CBS show this year - Hillary Rodham Clinton in February, and Barack Obama in January.