Why is Santa Claus so jolly? Because he knows where all the bad girls live. Doubtless he also knows a lot of old jokes, given the number of Christmas crackers there must be in his life. But while we might be inclined to grimace at their corniness, we do seem to have a fondness for well- worn gags. Why?

Old jokes shouldn't be viable, because, according to most humour theories, a joke needs an element of surprise. Immanuel Kant argued that a gag is born "from the sudden transformation of a strained expectation into nothing". Notice the word sudden. Kant wasn't much of a joker himself, apparently preferring to entertain his mates with accounts of his constipation. But he's not the only philosopher to suggest the importance of the unexpected. A century before, Thomas Hobbes argued that we laugh because of a feeling of "suddaine Glory arising from suddaine Conception of some Eminency in our selves, by Comparison with the Infirmityes of others". For a joke also reinforces our sense of our own worth.

More recently, the philosopher Simon Critchley made a similar point when he said that a joke creates laughter when the "stretching of the joke suddenly contracts into a heightened experience of the instant." So old jokes – or Joe Millers as they used to be called, after the 18th-century British book of corny gags – shouldn't work, should they? How can the punchline of an old joke be sudden; how can we be surprised by jokes we've heard before? We can't, but we still love them, and we're willing to laugh at them.

Most old jokes, particularly ancient jokes, aren't that funny. Certainly the world's oldest recorded joke doesn't raise many chuckles these days:

Something that's never been known since time immemorial: a young lady who doesn't break wind in her husband's lap.

This had them giddy with mirth in ancient Sumer (1900-1600 BC), but while the theme of flatulence is durable, the gag itself stinks. The same can be said of the oldest documented joke in England, an Anglo-Saxon riddle cited in the 10th century manuscript, The Exeter Codex:

Question: What hangs at a man's thigh and wants to poke the hole that it's often poked before?

Answer: A key.

While we recognise its double entendre as typically British, it's not exactly side-splitting. Likewise, most of the material in the world's oldest surviving joke book, the Philogelos, or "laughter-lover", wouldn't pass muster at The Comedy Store. This was written in Greek, and probably compiled in the fourth or fifth century by two joke enthusiasts, Hierocles and Philagrius. It contains 265 jokes, most of which would bomb today. This is because humour partly depends on context and shared cultural connections that don't always transcend time and geography. Lettuce, for instance, was hilarious to the ancient world (it was thought to be an aphrodisiac). However, even some really ancient jokes still have a degree of mileage:

A fool broke wind while in bed with a deaf person. When the latter caught the smell and began to complain, the fool said: "Come on, how could you hear it if you're supposed to be deaf?"

If you thought a theme was beginning to emerge, you'd be right. Some topics lend themselves to joking, and social taboos are particularly fertile ground. Issues that civilised society deems unacceptable can be safely addressed within the context of humour, and that's one of the reasons we enjoy, and need jokes.

There is no element of surprise if we know a joke, but we don't always need it. Pleasure results partly from the chance to jettison the shackles of propriety. A classic is a licence to laugh. Anthropologists have noticed that we need to feel that it's legitimate to laugh before we'll grant ourselves the privilege. This is why laughter is infectious; it is why they put canned laughter in sitcoms. "Laugh tracks increase the likelihood that you'll think a joke is funny and laugh at it," says Professor Robert Provine of the University of Maryland.

There's something about an old joke, or a classic comic scene, that – once we're aware of its status – can work like a laugh track, coaxing laughter out of us. This could also explain why some jokes have instantly recognisable forms and structures. Consider this, from the Philogelos:

A student dunce goes to the doctor and says, "Doctor, when I wake up, I'm all dizzy, then after half an hour I'm OK."

"Well," advises the doctor, "wait a half-hour before waking up."

This is the first recorded "doctor, doctor" joke, and it's another ancient gag that's still funny. Here's a favourite contemporary example of this type:

"Doctor, doctor... My son has swallowed my pen. What should I do?"

"Use a pencil until I get there."

The doctor, doctor set-up is corny, but it exists to signal the joke's status as a joke, and thus legitimise the laughter that's meant to result. There are other set-up strategies that function in the same way:

"I say, I say, I say... My wife's gone mad in Venezuela."

"Caracas?"

"Yes, absolutely loopy."

Variations of this include:

Jamaica? – No, she went of her own accord; Russian? – No, she's taking her time; Utrecht? – No, I walked.

Some claim the knock, knock structure has its origins with the Porter's speech in Shakespeare's Macbeth: "Knock, knock, knock! Who's there, i' th' name of Beelzebub?" And surely everyone can find a place in their heart for a good knock, knock joke?

"Knock, knock."

"Who's there?"

"Dishwasher."

"Dishwasher who?"

"Dishwasher way I spoke before I had false teeth."

The set-up phrase works to communicate humorous intent. Once again, it's corny, but suggests old, old suggests classic, and classic suggests that it's something we should laugh at too.

While people like to see themselves as culturally sophisticated, on the one hand, they also like to fit in. Joking enables us to bond with each other. Some scholars suggest that joking replaced social grooming as the main bonding device between early humans. Humour can facilitate and reinforce communal ties; we use jokes to make friends, a function so important that we don't let corniness get in the way. We make a big show of groaning at corny jokes, but corniness itself can be part of the fun. Sometimes a joke wouldn't make sense without it.

"What did the chicken say to the duck?"

"For pity's sake, don't cross the road or you'll never hear the last of it."

This is a meta-joke, or a joke about jokes, which, like all such jokes, depends on our knowledge of a particular joke form, and our awareness of its exhausted, clichéd status.

The earliest chicken-crossing-the-road joke emerged in the mid-19th century in an American magazine called The Knickerbocker, and there have been countless variations, many of which depend on our knowledge of the original. (I hear the duck later crossed the road in order to prove that he's not chicken. Sorry....)

Old jokes can still elicit mirth, and that might be worth bearing in mind this week as you pull your Christmas cracker. Don't throw the joke away with the plastic thimble. (You can tell I buy my crackers at Poundland). Use it to bond with your loved ones: it might go down better than you think.