The first inhabitants of the San Francisco area arrived around 3000 B.C. By the 16th century, when the first Europeans sailed along the California coast (always missing the Golden Gate due to fog), the area was inhabited by the Ohlone-speaking Yelamu tribe. The first westerners to see the bay were members of the 1769 Portola expedition. Seven years later, Juan Bautiza de Anza marched north from San Diego with a settlement party to establish a Spanish presidio and mission. By 1808 Mission San Francisco de Asis was the center of spiritual and material life for more than 1,000 neophytes drawn from local tribes.
In 1821, Mexico won its independence from Spain, cementing the decline of the mission era. In 1835 an American, William Richardson, became the first permanent resident of Yerba Buena. By the 1840s dozens more Americans came to Alta California and began agitating for independence. After a briefly declared "California Republic," they welcomed the arrival of James B. Montgomery, a U.S. Navy captain who came ashore on July 9, 1846, to raise the U.S. flag in Yerba Buena's plaza (today's Portsmouth Square).
On January 24, 1848, the first gold was found at Sutter's Fort, in the California foothills. Within months, San Francisco (renamed from Yerba Buena in 1847) became the central port and depot of the frenzied Gold Rush. Over the next year, arriving "forty-niners" increased the city's population from 1,000 to 25,000. The city was lawless and wild, its Barbary Coast district full of prostitution and gambling. Six major fires broke out between 1849 and 1851. In 1859 the silver boom of Nevada's Comstock Lode again filled the city's docks and lined its pockets. Construction of the Central Pacific Railroad-funded by the "Big Four" businessmen Charles Crocker, Mark Hopkins, Collis P. Huntington and Leland Stanford- drew thousands of laborers from China. Although many were later forced to leave by exclusionary U.S. policies, San Francisco's thriving Chinatown quickly became the largest Chinese settlement outside of Asia. The city expanded as cable cars enabled the city’s grid to spread over its steepest hills. In 1887 planners carved out 1,000 acres on the Pacific side of the peninsula for Golden Gate Park.
On April 18, 1906, the San Andreas Fault slipped more than 10 feet, unleashing a massive earthquake later estimated at 7.8 on the Richter scale. The tremors broke water mains and triggered fires that raged for four days, killing 3,000 people, destroying 25,000 buildings and leaving 250,000 homeless. The city rebuilt quickly with an improved city center and hosted the lavish Panama International Exposition just nine years later. The 1930s saw growth both in the city and its outlying communities, and the construction of the iconic Golden Gate and San Francisco Bay Bridges.
San Francisco was the main point of embarkation for World War II's Pacific theater, and the region became a major arms production center. After Pearl Harbor, the city's Japanese residents were forced into internment camps far inland. Their abandoned neighborhood was soon filled by African Americans arriving from the South to work in the war industries. The city also played a key role in the transition from World War II to the Cold War, hosting the 1945 conference at which the U.N. Charter was drafted and continuing to draw workers to develop technologies for the nuclear age.
San Francisco has maintained its reputation as a center of cultural bohemianism. In earlier years it had drawn writers from Mark Twain to Jack London, and it became a center for the 1950s.