The lack of affordable homes — for rental and purchase — in many major housing markets is a hurdle for young millennials as well as for baby boomers who hope to retire.

Trulia has studied the 100 largest housing markets across the country to see if they could find a potential solution to housing issues for the two largest generations.

Trulia’s premise is that multigenerational housing could work even for non-relatives or “boom-mates.” The suggestion is that baby boomers could increase their income in retirement or during the period leading up to retirement by renting out one or more rooms in their homes. Millennials could benefit because typically a rented room costs less than a one-bedroom apartment.

Trulia’s calculations found that baby boomers could earn as much as $14,000 a year by renting a room, while millennials could save up to $24,000 annually by renting a room instead of an apartment.

Researchers at Trulia looked for homes owned by baby boomers with at least two bedrooms more than the number of occupants — under the theory that these homeowners would want one extra bedroom for guests or a home office and could rent the other empty rooms. The researchers found nearly 3.6 million unoccupied rooms that could be rented.

When looking at the 100 largest housing markets, Salt Lake City leads with the most available bedrooms for rent, at 7.7 percent of all owner-occupied homes. Silver Spring, Md., and the District were ranked second and fourth for the most available rooms for rent.

Tampa has the fewest spare rooms, with just 2.1 percent of all owner-occupied homes having a potential room rental.

Naturally, homeowners in the most expensive housing markets and with the most need for rentals can make the most money by renting out a room.

The top five cities where homeowners can charge the most include San Francisco, Oakland, Calif., New York City, Boston and Cambridge, Mass.

Renting a bedroom in San Francisco can bring in more than $1,800 a month. In the District, a spare bedroom can bring in $942 per month.

To read the full report, click here.

To pass on a tip or item, contact us at realestate@washpost.com and put “Town Square” in the subject line.