Andy Stitzer (Steve Carell) is the eponymous 40-year-old virgin. He lives alone, collects action figures, plays video games, and his social life seems to consist of watching Survivor with his elderly neighbors. He works in the stockroom at an electronics store called SmartTech. When a friend drops out of a poker game, Andy’s co-workers David (Paul Rudd), Cal (Seth Rogen), and Jay (Romany Malco) reluctantly invite Andy to join them. At the game, when conversation turns to past sexual exploits, Andy desperately makes up a story, but admits his virginity when he compares the feel of a woman’s breast to a “bag of sand”. Feeling sorry for him (but also generally mocking him), the group resolves to help Andy lose his virginity.
Throughout the next several days, the gang’s efforts prove to be unsuccessful, partly because all three men give Andy different and sometimes contradictory advice. Later, Cal advises Andy to simply ask questions when talking to women, which makes Andy seem mysterious. His advice proves to be the most helpful, when Beth (Elizabeth Banks), a bookstore clerk, takes a liking to Andy. Andy starts to open up, and begins to form true friendships with his co-workers. David continues to obsess over his ex-girlfriend, Amy (Mindy Kaling). After meeting her unexpectedly during a speed-dating event attended by the group, he has an emotional breakdown while making a sale and is subsequently sent home by store manager Paula (Jane Lynch), who promotes Andy to fill in for him. Jay, seeing Andy’s continued reluctance to approach female customers, attempts to force the issue by hiring Andy aprostitute. When Andy discovers that Jay has inadvertently hired a transvestite, he is prompted to confront his friends, and tells them that he is taking matters into his own hands. Andy lands a date with Trish Piedmont (Catherine Keener), a woman he met on the sales floor who owns a store across the street. After Andy and Trish’s first date, in which they are interrupted by Trish’s teenage daughter Marla (Kat Dennings) as they are about to have sex, Andy decides to tell Trish he is a virgin. Before he can tell her, Trish suggests that they postpone having sex, to which Andy enthusiastically agrees; they decide they won’t have sex until their twentieth date. Meanwhile, Paula is impressed by Andy’s salesmanship and promotes him to floor manager.
As Andy draws closer to his twentieth date with Trish, his friends begin to deal with the consequences of their lifestyles. David, still spiraling in his obsession with Amy, has become disillusioned with sex and has taken a vow of celibacy, prompting Cal to lure him out by hiring an attractive young woman named Bernadette (Marika Dominczyk) to work in the stockroom. After overreacting during an argument with an obnoxious customer (Kevin Hart), Jay reveals that his girlfriend Jill broke up with him after learning he has been cheating on her. Andy comforts Jay, who says that sex can ruin a relationship. However, Jill later decides to take Jay back after learning she is pregnant. Andy and Trish’s relationship grows, and Trish suggests that Andy sell his collectible action figures in order to raise enough money to open his own store. When they finally reach the twentieth date, Andy is still reluctant and resists Trish, upsetting her. An argument ensues, in which Andy accuses Trish of pushing him into changing his life against his will, and Andy leaves for the nightclub where Jay is celebrating his girlfriend’s pregnancy. He quickly gets drunk, and after running into Beth, leaves for her apartment with her. Meanwhile, David finally relinquishes his celibacy and hooks up with Bernadette, and Trish’s daughter Marla convinces her to go and make up with Andy.
By this time Andy has sobered up and, after witnessing Beth’s methods of foreplay, he starts to have second thoughts. As Andy is leaving her bathroom, he finds his friends waiting outside, having followed to warn him about Beth and encourage him to go back to Trish. They leave together, and Andy returns to his apartment, where he finds Trish waiting for him. He attempts to apologize, but Trish, having found myriad suspicious belongings in his apartment, now thinks that Andy may be some sort of sexual deviant. Andy tries to convince her otherwise and declares his love for her, but she leaves in alarm and disgust. Andy chases after her on his bike but eventually runs headlong into the side of her car. Trish rushes to his side in concern, and he finally confesses to her that he is a virgin. She is surprised to learn that this is the reason behind his strange behavior, as she does not consider it to be important, and they kiss. Later, Andy and Trish are married in a lavish ceremony with everyone in attendance, with a sidelong mention of Andy’s action figures having sold for approximately half a million dollars. Afterwards, they consummate their marriage. The film ends with an over-the-top musical scene in which the cast of the film sing and dance to “Aquarius/Let the Sunshine In“.