The lizards were totally having sex. Kathryn Hahn knew it, and even the man who owned the lizards knew it, though he was trying to be very polite about the whole situation. Hahn and I stumbled upon this strange tableau — a man, bald and tattooed and wearing tube socks, sitting at the bottom of a narrow concrete staircase with two bearded dragons on his thigh, one perched on top of the other — when we were hiking in the hills above her house in Los Feliz last June. He told us that their names were Sun and Shine.

“Oh, my God, they’re so beautiful,” Hahn told the man. Then, with a wave: “Is something ... happening right now?”

“No,” the man said. “They’re just out for a sunbathe.”

Hahn, a human glow stick who radiates instant warmth to anyone in a 20-foot radius, explained that she was no stranger to bearded dragons, having cared for one from her son’s classroom. “They do have very messy craaaps,” she said, stretching out the last word to daffy effect.

Hahn was dressed like a cross between a power walker and a gardening enthusiast in white Adidas track pants, a ratty yellow 1979 Seattle SuperSonics T-shirt and an enormous straw sun hat with a chin strap. She kept flashing me a subtle sideways glance while curling up the right side of her mouth — a mischievous invitation. Hahn’s ability to conspire, both with other people onscreen and with the audience watching her, is one of her gifts. This sly expression earned Hahn plenty of work in her 20s, as the frumpish sidekick of the ingénue or the offbeat character in a spate of romantic comedies (“How to Lose a Guy in 10 Days,”1 “Win a Date With Tad Hamilton!” “The Holiday”). Back then, her glare played cynical and over-it, bitchy and incredulous. Now that Hahn is 46, the expression is softer and wiser. It says: Let’s stay in this scene for as long as we can. It says: We’re all just trying our best here, even this guy. It says: Let’s make hay out of this moment with Sun and Shine.

After the man was out of earshot, Hahn brought up the lizards again. She suggested that her photograph for this story be taken in front of “those two bearded dragons screwing.”

Hahn in “Mrs. Fletcher.” Sarah Shatz/HBO

It’s as good an image as any to capture Hahn’s recent career surge. Over the last six years, beginning with her starring role as Rachel, a sexually frustrated yuppie wife who buddies up to a young stripper in Jill Soloway’s first feature film, “Afternoon Delight,” and continuing through her work in TV series like “Transparent”2 and “I Love Dick” and movies like “Step Brothers” and “Private Life,” Hahn has boldly explored the intricacies — and comedy — of female desire with earthy naturalism and an enthusiastic lack of vanity. This month, HBO will begin showing “Mrs. Fletcher,”3 a series starring Hahn in the title role. Not only does she have to carry the show; she also has to do much of it solo. “Mrs. Fletcher” is, at its core, about a woman discovering her own sexuality in the privacy of her bedroom. It’s Hahn’s riskiest performance yet.

Later that day, as we walked back toward her home — an airy 1924 Mission-style house behind a prim hedgerow that she and her husband, the actor and writer Ethan Sandler,4 moved into about three years ago with their children, Leonard, 13, and Mae, 10 — I asked Hahn if she ever feels distant from the characters she plays. She thought about this for a moment before answering in the negative; if anything, she said, she fails to maintain enough distance between her own life and the lives she commits to the screen. “I struggle with anxiety and all that cocktail of depression,” she said. “There’s no separation. That’s why the work feels so cathartic.”

She suddenly stopped, scrunched up her face and laughed so hard that she snorted. “Oh, my God,” she cried out. “That is the worst sentence in the history of the world.” She started flapping her arms and galloping down the street, affecting a snooty accent and speaking in the third person, as if narrating a PBS documentary about herself. “Post her two-hour walk, she gathered her thoughts, and she started again: ‘And that’s why the work feels so cathartic.’ ”

Hahn is a font of silly voices and random asides. Sometimes she’ll transform into a 1940s movie star, cocking her head and speaking in a trans-Atlantic accent. Sometimes she’ll adopt a dotty English lilt as if she’s had too many cordials. She refers to her children almost exclusively as either “my peanuts” or “li’l [expletive].” And she regularly uses the word “bananas” as a way to express good-natured incredulity: “It’s bananas that I’ve been able to earn a living this way.”

The sort of raw, unadorned, often private sensuality that Hahn portrays so well feels like something new, a terrain that television has only recently begun to dig into. For decades, the small screen barely scraped the surface of women’s intimate lives — in 1952, in an episode of “I Love Lucy,” Lucille Ball had to announce she was pregnant without ever using the word or acknowledging out loud that babies come from intercourse. Even when TV sex became more explicit in the late ’90s, it was often played for comedic effect. “Sex and the City” broke many barriers and aired taboos — Funky spunk! The Rabbit! Promiscuity as aspirational lifestyle choice! — but the sex scenes were still rendered as farce. The bedroom on that show was a place of high silliness, of punch lines.

Over the last decade, however, viewers have gotten to see more complex, uncensored sexual dynamics play out, not for laughs but as a nuanced look at what really happens behind closed doors. A first-episode scene in “Girls,” in which Lena Dunham and Adam Driver are having a complex midcoitus debate about consent, for example, was a groundbreaking moment, a cable sex scene that wasn’t created for the male gaze. Since then, older women have begun to play around with their own erotic portrayal. There is a fresh demand these days for middle-aged actresses who can traverse the boundaries between sex and abuse, lust and power, carnality and clumsiness. This opened up space for an actress like Hahn.

For the first 15 years of her career, throughout the ’90s and early 2000s, Hahn was pigeonholed as the best friend, the comic relief, the weird girl, the drunk mom. After studying drama at Northwestern and Yale,5 and after a brief stint doing regional theater, Hahn’s stage career started to take off: She was offered a lead role in the national tour of “Proof.” But she and Sandler, who met in college, eventually found their way to Los Angeles. What followed were what she calls her “flailing years,” spent mostly playing supporting roles on TV shows like “Crossing Jordan.” “All of a sudden, I was on this weird best-friend train,” she says.

She did show up in major-studio films, but not in the kind of meaty roles that she dreamed of as a girl growing up in Cleveland Heights, when she developed a deep obsession with Teri Garr, Elaine May, Diane Keaton and Gena Rowlands,6 actresses who could balance screwball comedy and hot-blooded, unadorned sensuality. “Nothing felt polished,” she told me. “Nothing felt camera-ready or perfect.”

After years of playing the best friend, Hahn found a niche as a comedic character actress, adding a dash of zaniness to sitcoms like “Parks and Recreation” and films like “Bad Moms” and “Our Idiot Brother.” But it took a perceptive, risk-taking director, Soloway, to show Hahn that she had an inner ’70s heroine waiting to break out, that she could blend bathos and badinage. Soloway first spotted Hahn at the Silver Lake farmers’ market. Soloway (whose pronouns are they/them) had been searching for an actress to carry their first film, and several acquaintances suggested Hahn. “I had seen her before that on ‘Hung,’ ” Soloway told me, referring to Hahn’s brief stint on the HBO comedy about a male prostitute. “And she was pregnant and having sex and really just showing her body, and I remember thinking, This person has such a singular way of being an actress. She just felt so human. And then a couple of days later, I saw her at the market. I consider her to be a muse.”

Soloway cast Hahn as Rachel, the lead in “Afternoon Delight,” and for years afterward the two conspired through many projects to depict a kind of 360-degree, prismatic view of perimenopausal female sensuality and heartbreak. As Rachel, Hahn navigated the journey from sexual atrophy — she played an uptight stay-at-home mother who hasn’t slept with her husband in months — to reawakening (the film literally ends with an orgasm). Then came the part of the magnanimous Rabbi Raquel on “Transparent,” a gentle soul who wants to have a baby so badly that a miscarriage sends her into a black hole of sorrow.

In 2017, Hahn took on the role of Chris Kraus in “I Love Dick,” a Soloway adaptation of the book, whose author is also named Chris Kraus. “I Love Dick” is a story of sexual obsession: a married woman who stalks a rugged artist, lavishing him with erotic gifts and filthy letters. This allowed Hahn to embody an even edgier side of women’s eros — dangerous, abject, even vampiric. The next year, Hahn starred in Tamara Jenkins’s film “Private Life,” playing a woman struggling with infertility, whose maternal yearning cuts a chasm into her marriage, her friendships, her sense of self. Hahn gave an austere and skittery performance that felt voyeuristic to watch.

Hahn says that while she is surprised to be so busy in the back half of her career, it also makes sense that these roles are coming to her now, when there are “tectonic cultural plates that have shifted.” That she is in sudden demand has much to do with her talent, but also with being in the right place at the right time. “I happen to walk into a moment where it’s O.K. to be messy,” she says. “And contradictory and hypocritical and mad and confused and funny and still sexual and naked in all ways.”

Hahn and Sandler have been a couple for more than 25 years — she jokes that they started sharing a dorm room in college and just never stopped — but the centripetal force that has kept them together, she thinks, is an openness to adaptation, to big swerves. “I feel like I have remarried the same person a couple of times,” she says. “We just keep meeting each other as new human beings.”

In a way, this is the energy that animates all of Hahn’s recent work: this churning sense of flux, the idea that women in their 40s are not fixed entities but live wires. “It’s Hormones City, U.S.A.,” she says. “All of a sudden, you’re feeling things you haven’t felt before. Sex means something different now. Because it’s not just about having a baby, and that’s really interesting territory to mine.”

“Mrs. Fletcher” is based on a 2017 Tom Perrotta7 novel of the same name about a repressed suburban divorcée named Eve Fletcher who develops a pornography addiction after her son leaves for college. Eve is like a volcano in dormancy after years of self-sacrifice. She works at a senior-living facility, where she spends most of her day listening to octogenarians complain about sciatica. She has forgotten about her own youth, her own potential for reinvention.

But then something inside begins to rumble. In the pilot episode, a man with dementia gets in trouble at the senior center for watching an X-rated video on the lounge computer. Eve gives him a stern warning, but secretly she is intrigued by the concept of free online smut. Her apartment feels so empty now that her son is gone, and she tries to find things to do — she makes herself a nice dinner, takes a bubble bath, smokes a cigarette in the bubble bath — but she realizes she is bored, and more surprising, that she is horny. She slips into bed, wearing her glasses, and flips open her laptop. At first, she is repulsed by the images. But then — focusing her conspiratorial gaze on herself — she decides to click. She sees a naked woman, slams her computer down, before soon picking it up again, slowly. The way Hahn plays this moment is endearingly quiet; she shows Eve’s desire lapping at her like a gentle wave.

HBO told me that, at Hahn’s request, I could not be present while she filmed one of her many solo sex scenes. She only performs them with a few people in the room — including a sound tech with his or her back turned and the show’s intimacy coordinator,8 Claire Warden. “She’ll make sure that it’s closed monitors,” Hahn says, describing Warden’s responsibilities. “She’ll just double-check, double, triple, quadruple check. Then I completely can worry about the acting of it and can worry about being present.”

Hahn and Warden, whose job is a mix of movement coach, sex adviser and sentinel, spent a long time discussing and creating the ideal conditions in which Hahn could feel free to explore a kaleidoscopic range of sexual ideas, from floor positions to moaning techniques. Hahn was intent to show, as Warden explained recently, “an authentic story of a woman’s sexuality and self-pleasuring. Not performative or titillating but willing to find the truth, even if it is awkward or embarrassing.” Warden, who is 42, told me about crouching in a corner with the director of photography while Hahn practiced spanking her own bottom over a living-room chair — “holding our fists in our mouths because we were laughing so hard,” she said. “The ridiculousness of it! The sexiness! She’s trying to play both roles in the fantasy at the same time.”

In the second episode, Eve has to expel Roy, the porn-watcher with dementia played by the theater veteran Bill Raymond, from the home for being disruptive. I watched from a monitor as Hahn delivered seven perfect, wordless takes for the scene, showcasing her gift for blending humor and pathos; each offered the director, Liesl Tommy, a slightly different flavor of devastation. Another director shooting Hahn that day was Carrie Brownstein,9 who is an actor and a writer, as well as the guitarist in the punk band Sleater-Kinney. Brownstein told me that Hahn “is very kinetic. She reminds me in moments of Lucille Ball. She has a very wonderful grasp of the outer reaches of her fingers and toes.” Over and over, her face crumpling like failed origami as she swerved back and forth between silliness and vulnerability, Hahn warmed Raymond’s hands with her own through a car window.

Hahn struggles with how best to characterize this phase of her working life. “I certainly didn’t set out to be the poster person for women’s sexuality over 40,” she told me. “Sexuality is a piece of it. An important and splashy piece, but not the whole thing. It’s the desire and hunger I’m attracted to. A woman who wants.”

One day this summer, I met her in the lobby of the Bowery Hotel, in Lower Manhattan. She wore an oversize, rumpled white men’s shirt and a pair of billowy black vintage men’s pants. As we walked to an Italian place nearby, her gait was jangly and bright, like a handful of new pennies; she had forgotten to pack a brush for her trip, so her long brown hair was a wild bramble. The effect was that of Patti Smith dressed up as Charlie Chaplin for Halloween. At the restaurant, she asked the waitress about the asparagus soup — was it any good?

“Eh, it’s kind of bland,” the waitress responded.

As she walked away, Hahn leaned in over her cocktail. “I love radical honesty,” she whispered. “Anywhere I can get it.”