Most prospective homebuyers know that "cozy" is real estate code for tiny.

In San Francisco real estate, cozy is about all that most residents can afford. A person who wants to buy property in the city needs a household income of $303,000 in order to afford the 20% down payment on a $1.5 million home — the median sale price in San Francisco last quarter.

It should come as little surprise that cottages known as "earthquake shacks" are one of the most desirable real-estate assets in the city. After the 1906 earthquake and fires decimated some 500 city blocks and left half the population homeless, the city responded by building more than 5,000 small wooden cottages as temporary housing. They came to shelter over 16,000 people.

The surviving shacks are scattered across the city and fetch prices above $1 million.

Here's the story of how earthquake shacks came to be.