Thanks to astronomical housing prices, some are bunking with their parents or crashing on their friends' couches.

When Rachel Dallaire moved from the east coast of Florida to California's Silicon Valley, she assumed her $15,000-a-year salary bump would allow her to rent a modest, but nice, apartment near her new job at LEAD Elementary in San Mateo.

The first-grade teacher soon learned otherwise: First, she tried to find a place within walking distance of the school, but the $3,000-a-month price tags were daunting. Soon, she was debating details she'd taken for granted before, like choosing between units with a washer/dryer or ones with an oven. It was tough to find one with both. Dallaire ended up settling for a small in-law unit in nearby San Bruno; it's affordable and safe, but the studio layout means it's hard to tell where her bedroom ends and her living room begins. "I don't know how people do it without working two jobs," Dallaire said, who tutors and babysits around the area to earn extra income when she isn't preparing lesson plans.

Finding and keeping an affordable place to live can be an all-consuming chore in Silicon Valley. Some of the area's teachers, administrators, and teachers have to live two hours from school to find housing that fits their budget. Some combine two families into one apartment. Others move in with relatives. "They drive here when it's really early and (there's) little traffic. They sleep in their car for a few hours and then they start work," San Mateo Union High School District Superintendent Kevin Skelly says of some teachers who live more than 60 miles away. Other staff members are technically homeless. "We have teachers who are couchsurfing," he says. "It's brutal."

The technology boom is also pricing out educators, and many towns in the affluent area, which is dominated by suburban-style single-family homes, are reluctant to build more affordable housing. The median price for a one-bedroom rental in the greater San Jose metro area is $3,295 a month, according to analysis from rental website Zillow. Median home prices in Cupertino, where Apple is headquartered, are about $1.7 million. In Menlo Park, home of Facebook, it's $1.9 million. Palo Alto, near the campuses of Stanford University and Google, boasts a staggering median home price of $2.4 million.

Salaries have not kept up, even though California teachers make nearly $13,000 more per year than the national average, according to the National Center for Education Statistics. The lack of affordable housing has been worrisome for school districts struggling to attract talent from the rest of the nation.

To tackle the issue, some districts have taken an unusual approach: Building teacher- and staff-only apartment complexes, owned and operated by a school district. The San Mateo Union High School District is among the districts planning to build apartment complexes for their teachers after California Governor Jerry Brown signed into law last year a bill to assist school districts in creating affordable housing by using state and federal grants that were otherwise unavailable.

"It was an important piece of legislation to get authorized," San Mateo Community College spokesman Mitchell Bailey says, whose district has two apartment complexes for faculty and staff. The district often advises other educational entities in the area that are considering teacher housing. "It allows the conversation to continue, and it's going to be district-by-district to determine if they have the resources and, sometimes, the political will."

Other Silicon Valley and Bay Area public school districts have considered teacher housing, but not all have been able to get the surrounding public on board. Cupertino Union School District had been considering teacher housing, but Superintendent Wendy Gudalewicz says the district had to nix the plan due to "lack of community support."

The result means many teachers must live outside of the city where they teach—in some cases, a county or two away. About 21 percent of people who have jobs in Silicon Valley live outside of the area, and about 5 percent endure mega-commutes of more than 90 minutes one-way, according to the Silicon Valley Institute for Regional Studies, whose 2016 report was not job-specific.

A similar story—educators who can't afford to live where they teach—is playing out in other expensive metro areas across the nation. Several districts in high-cost parts of Colorado, such as Aspen, have experimented with subsidized housing for staff. In New York City, teachers often lean on organizations like TeacherSpaceNY, a real estate agency focused on finding teachers budget-friendly city pads. And in Washington D.C., a former college is being converted into an apartment complex that will offer lower-rent housing for city teachers. A nonprofit set up through a charter school development organization bought the property last year as a way to attract teachers to the city's charter schools. Plans are also underway in Chicago to transform a former elementary school in Humboldt Park into a "teachers village," with housing, shopping and continuing education centers, says Jose Cerda III, spokesman for real estate consultant firm IFF.

Back in Silicon Valley, physical education teacher Matt Labbie decided he could no longer afford to split a $4,000-a-month apartment with a few friends. "If you're spending most of your monthly income on rent, you have no way to save up for a down payment on a house," says Labbie. "It's just a dream."

But he was reluctant to give up a job, and an area, that he loved. So he took more extreme measures: He moved back in with his parents.