SAN JOSE, Calif. — Bay Area home prices are out of reach for many middle-income families, but surely if you are a highly prized engineer at Apple or Google you can afford a house here, right?

Not so fast.

These days even high-paid tech workers — the very people often blamed for driving up home prices — have to stretch to buy a house, according to a new study by Los Angeles-based real estate startup Open Listings. Techies do come closer to affording a pricey Silicon Valley home than teachers, service industry workers and scores of other workers. But homeownership may not be a given for them anymore, a shift that signals how the region's explosive housing costs are shutting out even the prosperous.

"These highly paid, highly coveted people that are being recruited from all over the country or the world, they're unable to afford the housing that's available nearby," said Open Listings CEO Judd Schoenholtz.

Software engineers at Bay Area tech companies including Apple, Google and Facebook would have to fork over more than 28 percent of their monthly salaries — a move frowned upon by financial experts — to pay for a home within a 20-minute commute from their office, according to the study. The average software engineer at Apple, for example, makes $188,000 a year and would have to spend 33 percent of his or her salary to afford a median-priced home in Cupertino, Calif., the study said. For software engineers at Reddit and Google, the mortgage and tax payments would total 32 percent of their income. Twitter engineers would have to fork over 30 percent, and Facebook engineers 29 percent.

Techies are unlikely to get much sympathy from other Bay Area workers struggling to make ends meet. Teachers, for example, who make a median salary of $72,340 a year, could afford just 0.4 percent of homes in San Francisco, according to an April study by Trulia.

But people whose mortgage payments exceed the recommended 28 percent of their income may have a hard time getting a home loan, Schoenholtz said. If they do get a loan, it may not be for the full amount of the price, which would force them to pony up more for a down payment. And for residents already paying high rent prices, saving up a standard 20 percent down payment is hard enough — not to mention a payment of 30 or 40 percent.

That means the dream of homeownership likely will elude some high-tech workers, which could hurt local companies' abilities to recruit and retain employees, Schoenholtz said.

"If that's not going to be attainable, I wonder what the long-term viability of these companies [is]," he said.

It's an issue already on the radar of many Bay Area tech companies. Last month, more than 100 tech executives and venture capitalists signed a letter supporting a bill by Sen. Scott Wiener, D-San Francisco, that would make it easier to build dense housing near transit stations.

"The lack of homebuilding in California imperils our ability to hire employees and grow our companies," the leaders wrote. "We recognize that the housing shortage leads to displacement, crushing rent burdens, long commutes and environmental harm, and we want to be part of the solution."

In Apple's hometown of Cupertino, for example, Zillow estimates the median home value is $2.2 million — up more than 20 percent from a year ago.

Several companies are taking the matter into their own hands. Facebook is planning to build 1,500 homes on its expanded Willow Campus in Menlo Park, and Google is backing the development of nearly 10,000 homes as part of its new office development at North Bayshore, in Mountain View.

For smaller companies without the resources to build housing of their own, leaving the area is a more cost-efficient option. That's what happened to Open Listings, the online real estate brokerage that authored the study. The startup was headquartered in the Bay Area in 2015 as it went through Mountain View-based accelerator Y Combinator. When the program was over, the founders decided to head down to Los Angeles instead of sticking around.

"We deliberately moved away from the Bay Area," Schoenholtz said. "We felt that it would be more affordable for our current and future employees to be located in a more diversely affordable location."