If you’re a Bay Area elementary school teacher, the number of places where you can afford to live has shrunk dramatically in the past six years.

The average Bay Area elementary school teacher earned $77,616 in 2018, according to the California Department of Education. On that salary, teachers can afford the median mortgage payment in just 16 of the 225-plus ZIP codes in the nine-county Bay Area and Santa Cruz County, according to our analysis of housing affordability data in partnership with Zillow. And that’s assuming they’ve saved a 20 percent down payment.

As the cost of housing has soared, Bay Area teachers — and the school districts who struggle to hire and keep them — have become poster children for the region’s affordability crisis. Three years ago, former Gov. Jerry Brown signed the “Teacher Housing Act of 2016” to make it easier for school districts to get into the business of being landlords. Some districts already have built housing. Others are working on similar plans. And a San Francisco startup that helps teachers afford down payments last year expanded its work to San Jose and eastern Contra Costa.

Read The Price We Pay: How Rising Housing Costs are Transforming the Bay Area

Despite those efforts, many teachers still struggle. San Jose Unified, which has proposed building affordable teacher housing on district property, has said it has to replace one of every seven teachers annually, given the rapidly rising cost of shelter. It’s worse in San Mateo, where Jefferson Union High School District has said housing costs have led to an annual turnover rate of 20 percent.

Not a single ZIP code in San Mateo, Santa Clara, Santa Cruz, San Francisco, Marin or Napa counties had a median mortgage payment that was affordable last year on an average elementary teacher’s income, our analysis showed. All 16 ZIP codes where elementary teachers could afford to buy are located in just four Bay Area counties: Alameda, Contra Costa, Solano and Sonoma.

In 2012, when Bay Area housing prices were hitting rock-bottom in the fallout from the economic crash, someone earning the region’s then-average salary for elementary school teachers of roughly $67,800 could afford the median mortgage payment in nearly a quarter of the Bay Area’s ZIP codes.

For teachers who are renting, the situation is worse. Today, if a teacher wants to rent — without roommates or other family income — the pool of affordable ZIP codes is even smaller than if they want to buy.

Just 12 ZIP codes, all in Solano and Contra Costa counties, have median rents of $1,940 or less, the amount someone on an income of $77,616 could spend each month without exceeding the recommended limit for housing expenses. Affordable is defined as spending no more than 30 percent of your pretax pay, the threshold commonly recommended by financial advisers.

Back in 2012, teachers who were renting could afford the median rent in more than one-third of Bay Area ZIP codes, including neighborhoods in Alameda, Contra Costa, Santa Clara, Solano and Sonoma counties.

The shrinking pool of affordable options means teachers have longer commutes. In 2012, a teacher working for an elementary school in Palo Alto and renting had a roughly 30-minute commute to the nearest affordable ZIP code, 95122, near East San Jose in Santa Clara County.

Today, that same teacher would have to drive more than hour and about 60 miles to reach the nearest affordable ZIP code — 94520, in Contra Costa County’s Concord.