Paul Manning (Walter Matthau), a successful suburban investment counselor, lives a comfortable and financially secure life with his beautiful, congenial, and perceptive wife, Ruth (Inger Stevens) and their daughter. Despite his happy marriage, Paul finds himself plagued by temptation and a wandering eye, a condition exacerbated by his affluent, mid-century suburban environment. His business is thriving, utilizing a secretary and a pool of eight typists.
The temptation hits close to home when Irma Johnson (Sue Ane Langdon), a bold woman within their social circle, unabashedly flirts with Paul at a party. Ruth instantly notices the behavior and openly discusses it with Paul later, amusedly pointing out how transparent and obvious Irma is in her intentions.
Paul's friend and neighbor, Ed Stander (Robert Morse), a smooth-talking and unrepentant serial adulterer, notices Paul's restlessness and initiates him into a subculture of married men who view infidelity as a sophisticated sport. Ed claims that "the code" grants men total immunity to openly boast about and share their affairs within their inner circle. Over a series of lunches and strategy sessions, Ed lays out a meticulous, corporate-style methodology required to execute a clean encounter without getting caught. Ed's rigorous logistical checklist includes renting secondary vehicles under fake names to avoid detection, scouting anonymous motels outside their social radius (the "hideaway"), utilizing olfactory countermeasures by matching specific aftershaves, and establishing rock-solid corporate alibis to justify leaving the house at night.
To illustrate his points, Ed shares a series of cautionary tales and success stories, presented as comedic vignettes featuring various 20th-century entertainment personalities:
Rance (Carl Reiner) is a nationally known movie star who targets "Miss Stardust" (Linda Harrison), a new actress recently hired by his film studio. To ensure the young starlet's success and cooperation with their top star, Rance's talent agent explicitly advises her on the logistics, explaining that a private liaison with the famous actor is the surest way to secure her career longevity. To protect Rance's public image and keep the encounter hidden from his wife, the pair execute an elaborate travel strategy: they depart Los Angeles in completely opposite directions, utilizing a complex web of different commercial flight paths and land routes to mask their trail. However, the exact moment Rance finally catches up with Miss Stardust at a remote alpine ski villa, his wife and a team of photographers instantly ambush him with flashing camera bulbs before the affair can even be consummated.
A stingy husband (Jack Benny) avoids a messy confrontation by using his legendary real-life cheapskate persona, fabricating a tale of financial ruin to persuade his mistress to voluntarily pack her bags, allowing him to immediately pick up his next companion waiting in the car.
A reckless husband (Terry-Thomas) breaks the cardinal rule by bringing his mistress (Jayne Mansfield) into his marital home. When they lose her uniquely proportioned brassiere, he undergoes a frantic, heart-stopping room sweep that literally turns his hair completely white from panic, noted when Ed introduced him later to Paul.
A brazen husband (Joey Bishop) masterfully employs psychological warfare against his wife (Ann Morgan Guilbert). When caught red-handed in the marital bed, he executes a relentless strategy of "deny, deny, deny", successfully gaslighting his wife into believing she is hallucinating until she apologizes to him.
As Paul absorbs these lessons, he begins to actively plan his first affair, targeting Jocelyn (Elaine Devry), a dark-haired, attractive new client who recently came to his financial planning firm. Paul successfully orchestrates the rendezvous and drives Jocelyn to the hideaway motel. However, once inside the room, reality sets in. As Jocelyn casually strips down to a corset, Paul becomes completely paralyzed by guilt and discomfort. Instead of embracing the moment, an anxious Paul can only talk about his wife, Ruth, inadvertently praising her virtues to his erstwhile paramore, while visibly uncomfortable with actually going through with the act.
Before the encounter can go any further, Paul and Jocelyn are suddenly interrupted by a chaotic commotion and shouting coming from the motel room right next door. Looking out the window, Paul witnesses a massive ambush: his friend Ed used Paul's hideaway and has been caught red-handed in bed with none other than Irma Johnson, raided by private investigators bursting into the room to document the cheating with an onslaught of flashing camera bulbs.
Witnessing Ed's catastrophic personal and legal ruin unfolding just feet away, Paul is thoroughly shaken out of his trance. Realizing that the psychological, moral, and logistical toll of infidelity completely destroys a man's peace of mind—and knowing how sharp his own wife is—he rejects the toxic logic of the suburban swinging lifestyle. Terrified of a similar fate, Paul hastily ushers Jocelyn out of the motel room, drives her back to her parked car, and unceremoniously dumps her off at her vehicle before speeding away.
Paul runs straight home to climb into bed with Ruth, recognizing that he already has everything he needs. In the final scene, Paul returns to his thriving investment business. Symbolizing his total reformation, he physically turns his back on his secretary during dictation and refuses to take the elevator to avoid encountering his female clerical staff, having completely opted out of the cheating network.