This idiom for a no-win situation came from a popular novel written by Joseph Heller in 1961. Hollywood turned Heller’s novel into a movie in 1970 starring Alan Arkin, Martin Balsam, Richard Benjamin, and Art Garfunkel. It is one of the best antiwar films in spite of its wry black comedy. The story concerns a medium-bomber group in the Mediterranean during World War II. Alan Arkin as Yossarian is a perplexed pilot whose life is ruled by the military regulation that states flight crews must report for duty unless excused for reason of insanity, but that anyone claiming such an excuse must, by definition, be sane.

Joseph Heller (1923-1999) enlisted in the U.S. Air Force as a bombardier after high school. He flew more than 60 bombing missions during his tour of duty in WWII. In his novel Heller has an army doctor explain regulation No. 22 to Yossarian.

“There was only one catch and that was Catch-22, which specified that a concern for one's safety in the face of dangers that were real and immediate was the process of a rational mind. Orr was crazy and could be grounded. All he had to do was ask; and as soon as he did, he would no longer be crazy and would have to fly more missions. Orr would be crazy to fly more missions and sane if he didn't, but if he was sane he had to fly them. If he flew them he was crazy and didn't have to; but if he didn't want to he was sane and had to.”
Yossarian was moved very deeply by the absolute simplicity of this clause of Catch-22 and let out a respectful whistle.
"That's some catch, that Catch-22," he observed.
"It's the best there is," Doc Daneeka agreed.

We have other examples of Catch-22 in real life. Take the government rule that requires workers to expose any wrongdoing in their office, but prevents them from doing so, because they are not allowed to disclose any information about their work. A paradoxical situation of Catch-22 is illustrated by factories that want to hire only workers who had experience making computers, but the only way to get the experience was by working at the computer factory.