It is a role-play exercise, with a punster and a recipient of wit.
The standard format has five lines:
- The punster: Knock knock!
- The recipient: Who's there?
- The punster: a variable response, sometimes involving a name (Doctor)
- The recipient: a repetition of the response followed by who? (Doctor who?)
- The punster: the punch line, which typically involves a pun-based misusage of the word set up during the response (How did you know?!)
The exact date of the joke formula attaining popularity is unknown, but was likely 1936. Fred Allen's December 30, 1936 radio broadcast included a humorous wrapup of the year's least important events, including a supposed interview with the man who "invented a negative craze" on April 1st: "Ramrod Dank... the first man to coin a Knock Knock."
"Knock knock" was the catchphrase of music hall performer Wee Georgie Wood, who was recorded in 1936 saying it in a radio play, but he simply used the words as a reference to his surname and did not use it as part of the well-known joke formula. The format was well known in the UK and US in the 1950s and early 1960s before falling out of favour. It then enjoyed a renaissance after the jokes became a regular part of the badinage on Rowan & Martin's Laugh-In.
In 2010, a letter from a steward (thought to be Jim Richardson) on the Nahlin steam yacht was discovered. The 16-page letter to his mother detailed life on the yacht during a 1936 Mediterranean cruise on which King Edward VIII and Wallis Simpson were passengers. The steward repeated a popular joke of the time: "Knock knock. Who's there? Edward Rex. Edward Rex who? Edward wrecks the Coronation."
In France, the punchline is sometimes a pun on the title of a popular song, allowing the last answer to be sung :
Toc Toc! (Knock knock!)
Qui est là? (Who's there?)
Sheila qui? (Sheila who?)
Sheila lutte finale... . (a pun on "c'est la lutte finale" (It's the final struggle), the first line of the chorus of The Internationale)
In Shakespeare's play Macbeth a comic relief character delivers a twenty-line monologue and satire that makes reference to events of that time. It follows the pattern of "knock knock who's there?" but it is done entirely by the character and knocks from off stage. The character is a hung over porter (in most performances drunk, but in the original he was hung over) who pretends he is the porter to the gates of hell welcoming sinners of different professions:
(Macbeth ActII, sciii)
Knock, knock, knock! Who's there, i' th' name of Beelzebub? Here's a farmer that hanged himself on the expectation of plenty. Come in time, have napkins enough about you, here you'll sweat for 't.
(this is a joke referring to a price drop in crops, as well as a joke about the heat in hell)
Knock, knock! Who's there, in th' other devil's name? Faith, here's an equivocator that could swear in both the scales against either scale, who committed treason enough for God's sake, yet could not equivocate to heaven. O, come in, equivocator.
(this passage is believed to be a reference to a trial of the Jesuits who were charged with equivocation speaking unclearly or speaking with double meaning)
Knock, knock, knock! Who's there? Faith, here's an English tailor come hither for stealing out of a French hose. Come in, tailor. Here you may roast your goose.
(the tailor is accused of stealing cloth while making breeches, this is a joke about a fashion trend in Shakespearian times, also a pun for roasting the tailor's iron with the heat of hell)