First, there are the elements that both the reader and the characters find humorous. This is the kind of humor you find almost everywhere: even (especially) in the most tense of situations, people throw off quips and one-liners. It's probably the most appropriate to stories that aren't intended to be comedic, a moment of tension release. Personally, for me the tricky part is balancing the reactions of the other characters - to have them ignore such humor seems peculiar, but on the other hand, I don't want their reactions to be too broad. That ends up somewhere between self-congratulatory and a sitcom laugh track.
Second, there are elements that the reader finds funny, but the characters do not - whether because it references an anachronism / bit of modern culture, it involves in-story knowledge that the reader has but the character does not, or simply that it's something you can only laugh at with distance. I do a lot of this in Hero - though I'm always cautious with the pop culture references, because I know they may be incomprehensible a few years down the road. Still, there's a mild dig at creationism that I think has some life yet to it ...
Third, there are elements that the characters find funny, but the reader does not. This is probably not really humor so much as worldbuilding: it points to ingrained stereotypes and shorthand in the characters' culture(s). And it can be built up into the other kinds of humor: if character X makes cracks about culture Y's love for beer, you can already anticipate what's about to happen when a native from that land shows up ...
It's this last that I haven't played with much - about the closest I've come is that there's a certain understanding that songs from Evinnen are very much like classic Celtic tunes: depressing and full of woe. That leads to the following exchange, which also touches upon the second kind of humor in drawing a parallel to another genre of music in our contemporary world:
“Matheus, Matheus!” The inventor Valchem’s face lit with a child’s enthusiasm. “What happens if you take a traditional Evinneni song and play it backwards?”
“You get your life back, you get your health back, you get your true love back?” the hero hazarded.
In any case, it's definitely something I want to work with more. Obviously, characters laughing at something the reader doesn't "get" can become tiresome fast, but it's a nice level for worldbuilding. Anyone have any nice examples of this?