Here's how long it would take the average person to save enough to buy a home in San Francisco

San Francisco, California.
Sean Pa

If you're thinking about buying a house in the Bay Area, it's going to cost you. Home investment company Unison's 2018 Home Affordability Report found that the San Francisco metro area is the "least affordable in the country, with an annual salary of $231,216 needed to buy the median home." If you zoom in on the city itself, that number grows to a whopping $349,650.

Unison's index determines how affordable a given market is by estimating how long it would take a person earning the median salary to buy a home at the median price, assuming a 5 percent savings rate.

It would take the average person 20 years to be able to save up a 10 percent down payment, according to their calculations.

Even those currently bringing in six figures struggle to afford housing in the Bay Area. In 2017, an anonymous San Francisco-based Twitter employee earning $160,000 reported that he was barely scraping by.

"I didn't become a software engineer to be trying to make ends meet," he told The Guardian.

The employee's biggest expense is the $3,000 monthly rent he pays on a two-bedroom house where he lives with his wife and two kids, which he describes as "ultra cheap."

Another woman who spoke to The Guardian says that although she and her partner make a combined salary of over $1 million, they can't afford a house. "This is part of where the American dream is not working out here," she says.

Here's why a Silicon Valley tech exec says to fix California’s housing crisis, scrap the $64 billion bullet train

The affordability issue has become so severe that residents are fleeing the state in droves. Between July 2016 and July 2017, California saw a net loss of over 138,000 people, according to data from the Census Bureau.

Even those who want to stay find it difficult to find a place to live.

"The rate at which California has been losing people to other states has accelerated in the past couple of years, in part because of rising housing costs," Jed Kolko, chief economist with employment website, told CNBC's Jeff Daniels.

Don't miss: You need to earn $418,000 to buy a home in NYC—here's what you need in other major US cities

Like this story? Like CNBC Make It on Facebook!

Here's what $1.3 million can buy you in real estate in the U.S.'s biggest metropolitan areas