IT was like one of those magical blind-date scenes out of a Hollywood rom-com, without the “rom.” I met Brian, a New York screenwriter, a few years ago through work, which led to dinner with our wives and friend chemistry that was instant and obvious.

We liked the same songs off Dylan’s “Blonde on Blonde,” the same lines from “Chinatown.” By the time the green curry shrimp had arrived, we were finishing each other’s sentences. Our wives were forced to cut in: “Hey, guys, want to come up for air?”

As Brian and his wife wandered off toward the No. 2 train afterward, it crossed my mind that he was the kind of guy who might have ended up a groomsman at my wedding if we had met in college.

That was four years ago. We’ve seen each other four times since. We are “friends,” but not quite friends. We keep trying to get over the hump, but life gets in the way.

Our story is not unusual. In your 30s and 40s, plenty of new people enter your life, through work, children’s play dates and, of course, Facebook. But actual close friends — the kind you make in college, the kind you call in a crisis — those are in shorter supply.

As people approach midlife, the days of youthful exploration, when life felt like one big blind date, are fading. Schedules compress, priorities change and people often become pickier in what they want in their friends.

No matter how many friends you make, a sense of fatalism can creep in: the period for making B.F.F.’s, the way you did in your teens or early 20s, is pretty much over. It’s time to resign yourself to situational friends: K.O.F.’s (kind of friends) — for now.

But often, people realize how much they have neglected to restock their pool of friends only when they encounter a big life event, like a move, say, or a divorce.

That thought struck Lisa Degliantoni, an educational fund-raising executive in Chicago, a few months ago when she was planning her 39th birthday party. After a move from New York to Evanston, Ill., she realized that she had 857 Facebook friends and 509 Twitter followers, but still did not know if she could fill her party’s invitation list. “I did an inventory of the phases of my life where I’ve managed to make the most friends, and it was definitely high school and my first job,” she said.

After a divorce in his 40s, Robert Glover, a psychotherapist in Bellevue, Wash., realized that his roster of friends had quietly atrophied for years as he focused on career and family. “All of a sudden, with your wife out of the picture, you realize you’re lonely,” said Dr. Glover, now 56. “I’d go to salsa lessons. Instead of trying to pick up the women, I’d introduce myself to the men: ‘Hey, let’s go get a drink.’ ”

In studies of peer groups, Laura L. Carstensen, a psychology professor who is the director of the Stanford Center on Longevity in California, observed that people tended to interact with fewer people as they moved toward midlife, but that they grew closer to the friends they already had.

Basically, she suggests, this is because people have an internal alarm clock that goes off at big life events, like turning 30. It reminds them that time horizons are shrinking, so it is a point to pull back on exploration and concentrate on the here and now. “You tend to focus on what is most emotionally important to you,” she said, “so you’re not interested in going to that cocktail party, you’re interested in spending time with your kids.”

As external conditions change, it becomes tougher to meet the three conditions that sociologists since the 1950s have considered crucial to making close friends: proximity; repeated, unplanned interactions; and a setting that encourages people to let their guard down and confide in each other, said Rebecca G. Adams, a professor of sociology and gerontology at the University of North Carolina at Greensboro. This is why so many people meet their lifelong friends in college, she added.

In the professional world, “proximity” is hard to maintain, as work colleagues are reassigned or move on to new jobs. Last year, Erica Rivinoja, a writer on the NBC series “Up All Night,” became close with a woman, Jen, when they worked together on a pilot. Almost instantly, they knew each other’s exercise schedules and food preferences. Jen could sense when Ms. Rivinoja needed a jolt of caffeine, and without asking would be there with an iced tea.

“But as soon as the pilot was over, it was hard to be as close without that constant day-to-day interaction,” said Ms. Rivinoja, 35. They can occasionally carve out time for a quick gin and tonic, she said, but “there aren’t those long afternoons which bleed into evenings hanging out at the beach and then heading to a bar.”

The workplace can crackle with competition, so people learn to hide vulnerabilities and quirks from colleagues, Dr. Adams said. Work friendships often take on a transactional feel; it is difficult to say where networking ends and real friendship begins.

Differences in professional status and income also complicate matters. “It really does get weird when your friends are making tons more than you, or tons less,” said Adriane Duckworth, a former marketing executive now working as an artist in Hamilton, Ontario. She recently welcomed a promising new couple into her circle of friends, but they quickly turned people off with their obsession with money.

“At our wedding, other friends of ours who were seated with them actually complained to us afterward about the couple who was asking everyone how much money they made,” said Ms. Duckworth, 32. “People who made less felt uncomfortable discussing it, and people who made the same or more just felt it was weird to talk about it so nonchalantly.”

Once people start coupling up, the challenges only increase. Making friends with other couples “is like matchmaking for two,” said Kara Baskin, a journalist who works in Boston. “Not only are you worrying about whether the other woman likes you, you’re also worrying if her husband likes you, if your husband likes her, if your husband likes him.”

Not long ago, she invited her husband’s new work buddy over for dinner with his wife. But the wife was visibly unimpressed by Ms. Baskin’s half-furnished home (they had just moved in) and thrown-together spaghetti dinner. “It was basically clear that his wife had been cajoled into attending,” said Ms. Baskin, 33. “She settled on to our rickety Ikea kitchen chairs like she was lowering herself into a coal mine.”

The couple departed quickly after dessert. The next day at work, the husband made an excuse about his wife being tired. “But it was unspoken that we wouldn’t be seeking their company again,” Ms. Baskin said.

ADDING children to the mix muddles things further. Suddenly, you are surrounded by a new circle of parent friends — but the emotional ties can be tenuous at best, as the comedian Louis C. K. related in one stand-up routine: “I spend whole days with people, I’m like, I never would have hung out with you, I didn’t choose you. Our children chose each other. Based on no criteria, by the way. They’re the same size.”

Even when parent friends develop a bond, the resulting friendships can be fleeting — and subject to the whims of the children themselves.

Caryl Lyons, an event planner in Danville, Calif., and her husband found a budding friendship with a parent-friend couple hit a roadblock when their young sons, who had been close friends, drifted apart. When the families planned a barbecue together, her son would say, “Can I have my other friends over?” said Ms. Lyons, 44.

External factors are not the only hurdle. After 30, people often experience internal shifts in how they approach friendship. Self-discovery gives way to self-knowledge, so you become pickier about whom you surround yourself with, said Marla Paul, the author of the 2004 book “The Friendship Crisis: Finding, Making, and Keeping Friends When You’re Not a Kid Anymore.” “The bar is higher than when we were younger and were willing to meet almost anyone for a margarita,” she said.

Manipulators, drama queens, egomaniacs: a lot of them just no longer make the cut.

Thayer Prime, a 32-year-old strategy consultant who lives in London, has even developed a playful 100-point scale (100 being “best friend forever”). In her mind, she starts to dock new friend candidates as they begin to display annoying or disloyal behavior. Nine times out of 10, she said, her new friends end up from 30 to 60, or little more than an acquaintance.

“You meet someone really nice, but if they don’t return a call, drop to 90, if they don’t return two calls, that’s an immediate 50,” she said. “If they’re late to something in the first month, that’s another 10 off.” (But people can move up the scale with nice behavior, too, she added.)

Having been hardened by experience, many people develop a more fatalistic view of friendship.

“When you’re younger, you define what it really means to be friends in a more serious way,” said my screenwriter friend, Brian. (His full name is Brian Koppelman, and he wrote and is a co-director of “Solitary Man,” a 2010 film starring Michael Douglas about a middle-aged man trying to reconnect with friends and family.)

“My ideas of friendship were built by ‘The Godfather’ and ‘Diner,’ ” he said. “Your friends were your brothers, and anything but total loyalty at all costs meant excommunication. As you get older, that model becomes unrealistic.”

By that point, you have been through your share of wearying or failed relationships. You have come to grips with the responsibilities of juggling work, family and existing friends, so you become more wary about making yourself emotionally available to new people. “You’re more keenly aware of the downside,” said Mr. Koppelman, 46. “You’re also more keenly aware of your own capacity to disappoint.”

“I haven’t really changed my standards for what it means to actually be friends,” he concluded. “It’s just that I use the word ‘friends’ more loosely. Making the real kind, the brother kind, is much harder now.”

Some, like Ms. Degliantoni, the fund-raising executive, simply downsize their expectations. “I take an extremely efficient approach and seek out like-minded folks to fill very specific needs,” she said of her current strategy. “I have a cocktail friend and a book friend and a parenting friend and several basketball friends and a neighbor friend and a workout friend.”

“It’s much easier filling in those gaps in my life,” she added, “than doing an exhaustive approach for a new friend.”

Or, they hit rock bottom and turn back the clock to their breathlessly social 20s.

After a move to New York in his 30s, Dave Cervini, a radio station executive, was so lonely that he would walk his cat in Central Park, hoping to stoke conversations. Finding only curious stares, he decided to start the New York Social Network, an activities group for people to find friends by hanging out at Yankees games or wine-tasting mixers. The company now counts 2,000 members, most in their 30s. He considers 200 of them close friends.

“It takes courage for people to take the first step,” he said. “Hopefully, I make it easier, having been there myself.”

In that spirit, I recently called Brian. We joked about our inability to find time to hang out, and made a dinner date at the next available opening.