The phrase "when pigs fly" is an adynaton—a figure of speech so hyperbolic that it describes an impossibility. The implication of such a phrase is that the circumstances in question (the adynaton, and the circumstances to which the adynaton are being applied) will never occur.
"When pigs fly" is an adynaton, a way of saying that something will never happen. The phrase is often used for humorous effect, to scoff at over-ambition. There are numerous variations on the theme; when an individual with a reputation for failure finally succeeds, onlookers may sarcastically claim to see a flying pig. ("Hey look! A flying pig!")  Other variations on the phrase include "And pigs will fly," this one in retort to an outlandish statement.
An example occurs in the film The Eagle Has Landed: an Irish secret agent working for the Nazis replies to a German general speaking of Germany's shortly winning World War II, "Pigs may fly, General, but I doubt it!" Later, when the Irishman sees German soldiers parachuting before an attack, he says to himself, "Mother of God! Flying pigs!"
An identical phrase, used to express impossibilities, exists in Romanian, Când o zbura porcul, literally meaning "When the pig shall fly"; an equivalent also implying an animal is La Paștele cailor, literally: "on horses' Easter". Similar phrases in English include "when hell freezes over", the Latin expression "to the Greek calends," and "and monkeys might fly out of my butt", popularized in Wayne's World skits and movies. They are examples of adynata. In Finnish, the expression "kun lehmät lentävät" (when cows fly) is used because of its alliteration. In French, the most common expression is "quand les poules auront des dents" (when hens will have teeth).
In Polish, a similar expression is "See a tank rolling in here?", while simultaneously lowering a lower eyelid with a finger. Sometimes, when in return to this a slightly more limited, but still improbable answer is given, the speaker repeats the gesture, stating: "Maybe at least a gun barrel sticks out?":
"I'm sure that the cows will make a permanent colony on the Moon by the end of 2012."
"Yeah, sure. See a tank rolling in here?" (lowering the eyelid)
"Well, maybe not 2012, but 2013, surely."
"Maybe at least a gun barrel sticks out?" (repeating the gesture.)
The idiom is apparently derived from a centuries-old Scottish proverb, though some other references to pigs flying or pigs with wings are more famous. At least one appears in the works of Lewis Carroll:
"Thinking again?" the Duchess asked, with another dig of her sharp little chin. "I've a right to think," said Alice sharply, for she was beginning to feel a little worried. "Just about as much right," said the Duchess, "as pigs have to fly...." — Alice's Adventures in Wonderland, Chapter 9.
American literature author John Steinbeck was told by his professor that he would be an author when pigs flew. When he eventually became a novelist, he started to print every book he wrote with the insignia "Ad astra per alas porci" (to the stars on the wings of a pig).
Pink Floyd had a flying pig on the cover of the Animals album. This clearly ties in with the album's songs "Pigs On The Wing". Since then the group has used a flying pig as a prop for concerts. See Pink Floyd pigs.
This album cover is one of the many cultural references in the game Jet Set Willy; the Emergency Power Generator is a miniature indoor version of Battersea Power Station with a pig flying over it. That flying-pig sprite is also used in several other rooms.
In "Alice", a popular TV series based on the movie (1976–1985), "Alice Doesn't Live Here Any More". Alice (Linda Lavin) worked at Mel's Diner along with a spunky waitress named Flo (Polly Holliday). Flo spoke with a southern twang, and one of her favorite sayings was, "When Pigs Fly!"* A 1996 musical When Pigs Fly.
In The Simpsons episode, "Lisa the Vegetarian", Lisa pushes Homer's prize pig down a hill into a river, where it ends up getting shot through the air by a dam's spillway suction. In his office Mr Burns says to Smithers he would like to do something charitable with his wealth. When Smithers questions this, he answers "when pigs fly." The pig then passes his window in flight, at which point he admits he would still like to keep his money.
As a reference to the phrase, in the game Viva Piñata, you can obtain a Pigxie, a pig-like piñata with wings, by crossbreeding a Rashberry (piñata based on a pig) with a Swanana (piñata based on a swan).
In the UK BBC One series called ShakespeaRe-Told adaptation of Macbeth, the character Joe Macbeth's monologue "Is that a [police] helicopter? Is it landing on this building? Pigs will fly! Pigs will fly!" It is the film's translation of "The Birnam Wood" reference to the warning given to Macbeth in the Shakespeare play of the same name, in which he is warned that "Macbeth shall never vanquish'd be until / Great Birnam wood to high Dunsinane hill / Shall come against him."
Flying pigs were seen in the film Nanny McPhee and the Big Bang and were a large part of the promotion related to it, including its major promotional posters. The original Nanny McPhee film had featured the phrase "snow in August" as a similar reference to something that was supposed to be impossible.
The cover of Stephen Colbert's adult-targeted picture book I Am a Pole (And So Can You!) features an emblem stating that it is a "Caldecott Eligible Book" and a picture of Colbert riding a flying pig, a tongue-in-cheek reference to the book's actual likelihood of being nominated for this award.
In the game Jetpack Joyride, the gadget "Flying Pig" can be bought.
A flying pig appeared in several sketches in the third season of The Kids in the Hall, entertaining people waiting in long lines.