As of 2017, it was the seventh-highest income county in the United States, with a per capita personal income of $119,868.[20] As of 2015, San Francisco proper had a GDP of $154.2 billion, and a GDP per capita of $178,479.[21][22] The San Francisco CSA was the country's third-largest urban economy as of 2017, with a GDP of $907 billion.[23] Of the 500+ primary statistical areas in the US, the San Francisco CSA had among the highest GDP per capita in 2017, at $93,938.[23] San Francisco was ranked 16th in the world and third in the United States on the Global Financial Centres Index as of March 2019.[24]

The California Gold Rush brought a flood of treasure seekers (known as "forty-niners", as in "1849"). With their sourdough bread in tow,[38] prospectors accumulated in San Francisco over rival Benicia,[39] raising the population from 1,000 in 1848 to 25,000 by December 1849.[40] The promise of great wealth was so strong that crews on arriving vessels deserted and rushed off to the gold fields, leaving behind a forest of masts in San Francisco harbor.[41]
Some of these approximately 500 abandoned ships were used at times as storeships, saloons and hotels; many were left to rot and some were sunk to establish title to the underwater lot. By 1851 the harbor was extended out into the bay by wharves while buildings were erected on piles among the ships. By 1870 Yerba Buena Cove had been filled to create new land. Buried ships are occasionally exposed when foundations are dug for new buildings.[42]

California was quickly granted statehood in 1850, and the U.S. military built Fort Point at the Golden Gate and a fort on Alcatraz Island to secure the San Francisco Bay. Silver discoveries, including the Comstock Lode in Nevada in 1859, further drove rapid population growth.[43] With hordes of fortune seekers streaming through the city, lawlessness was common, and the Barbary Coast section of town gained notoriety as a haven for criminals, prostitution, and gambling.[44]

Entrepreneurs sought to capitalize on the wealth generated by the Gold Rush. Early winners were the banking industry, with the founding of Wells Fargo in 1852 and the Bank of California in 1864. Development of the Port of San Francisco and the establishment in 1869 of overland access to the eastern U.S. rail system via the newly completed Pacific Railroad (the construction of which the city only reluctantly helped support[45]) helped make the Bay Area a center for trade. Catering to the needs and tastes of the growing population, Levi Strauss opened a dry goods business and Domingo Ghirardelli began manufacturing chocolate. Immigrant laborers made the city a polyglot culture, with Chinese Railroad Workers, drawn to "Old Gold Mountain", creating the city's Chinatown quarter. In 1870, Asians made up 8% of the population.[46] The first cable cars carried San Franciscans up Clay Street in 1873. The city's sea of Victorian houses began to take shape, and civic leaders campaigned for a spacious public park, resulting in plans for Golden Gate Park. San Franciscans built schools, churches, theaters, and all the hallmarks of civic life. The Presidio developed into the most important American military installation on the Pacific coast.[47] By 1890, San Francisco's population approached 300,000, making it the eighth-largest city in the United States at the time. Around 1901, San Francisco was a major city known for its flamboyant style, stately hotels, ostentatious mansions on Nob Hill, and a thriving arts scene.[48] The first North American plague epidemic was the San Francisco plague of 1900–1904.[49]

At 5:12 am on April 18, 1906, a major earthquake struck San Francisco and northern California. As buildings collapsed from the shaking, ruptured gas lines ignited fires that spread across the city and burned out of control for several days. With water mains out of service, the Presidio Artillery Corps attempted to contain the inferno by dynamiting blocks of buildings to create firebreaks.[50] More than three-quarters of the city lay in ruins, including almost all of the downtown core.[27] Contemporary accounts reported that 498 people lost their lives, though modern estimates put the number in the several thousands.[51] More than half of the city's population of 400,000 was left homeless.[52] Refugees settled temporarily in makeshift tent villages in Golden Gate Park, the Presidio, on the beaches, and elsewhere. Many fled permanently to the East Bay.

Urban planning projects in the 1950s and 1960s involved widespread destruction and redevelopment of west-side neighborhoods and the construction of new freeways, of which only a series of short segments were built before being halted by citizen-led opposition.[60] The onset of containerization made San Francisco's small piers obsolete, and cargo activity moved to the larger Port of Oakland.[61] The city began to lose industrial jobs and turned to tourism as the most important segment of its economy.[62] The suburbs experienced rapid growth, and San Francisco underwent significant demographic change, as large segments of the white population left the city, supplanted by an increasing wave of immigration from Asia and Latin America.[63][64] From 1950 to 1980, the city lost over 10 percent of its population.

Two recent decades have seen two booms driven by the internet industry. First was the dot-com boom of the late 1990s, startup companies invigorated the San Francisco economy. Large numbers of entrepreneurs and computer application developers moved into the city, followed by marketing, design, and sales professionals, changing the social landscape as once-poorer neighborhoods became increasingly gentrified.[72] Demand for new housing and office space ignited a second wave of high-rise development, this time in the South of Market district.[73] By 2000, the city's population reached new highs, surpassing the previous record set in 1950. When the bubble burst in 2001, many of these companies folded and their employees were laid off. Yet high technology and entrepreneurship remain mainstays of the San Francisco economy. By the mid-2000s (decade), the social media boom had begun, with San Francisco becoming a popular location for tech offices and a common place to live for people employed in Silicon Valley companies such as Apple and Google.[74]