Add information to a piece of dialogue. This expands what's happening and can lead to further ideas for a character and scene. For example, if one character's line is "That's a nice hat you have," your character's line might be, "Thanks, I love it too." A funny ad-lib for your character could be, "But gee, I feel bad that I stole it from that kid over there." This adds information to a scene and opens it up to further possibilities.
Ad-lib specific dialogue. Jokes are often funny because they're so specific. While, "She's just really into tacos" might be funny, "She's really into tacos with 3 pounds of lettuce" is funnier, because it's more specific.
Keep ad-libs brief. A line or two of dialogue is enough. Ad-libbing a long speech throws things off.
Play along with how the other actors ad-lib. This creates a team atmosphere and leads to funnier combinations. Denying what someone says throws ad-libbing off track. For example, if a character says, "I'm president of the United States," and you say, "No, you're not. You're a minor league umpire," while that might be funny, it can throw ad-libbing off track. If you'd like to follow a similar theme, instead say, "And to think, just four years ago you were a minor league umpire."
Avoid trying to one-up the other actors. Ad-libbing can become difficult to watch if the actors try to continually top each other. Be a team player. Help the scene improve. Don't try to steal the spotlight.