The City and County of San Francisco is the 4th most populous city in California and the 14th most populous city in the United States, with a 2006 estimated population of 744,041. One of the most densely populated major cities in the U.S., San Francisco is part of the much larger San Francisco Bay Area, which is home to approximately 7.2 million people. The city is located on the tip of the San Francisco Peninsula, with the Pacific Ocean to the west, the San Francisco Bay to the east, and the Golden Gate to the north. The U.S. Geological Survey National Mapping Information locates the city of San Francisco at 37° 46' 00" N 122° 26' 00" W.

In 1776, the Spanish settled the tip of the peninsula, establishing a fort at the Golden Gate and a mission named for Francis of Assisi. The California Gold Rush in 1848 propelled the city into a period of rapid growth. After being devastated by the 1906 earthquake and fire, San Francisco was quickly rebuilt.

San Francisco is a popular international tourist destination renowned for its steep rolling hills, an eclectic mix of Victorian and modern architecture, and a cosmopolitan population that is highly diverse both ethnically and in sexual orientation. While the climate includes chilly summer fog, the winters are mild. Famous landmarks include the Golden Gate Bridge, Alcatraz Island, the cable cars, Coit Tower, and Chinatown.

The earliest archaeological evidence of inhabitation of the territory of the city of San Francisco dates to 3000 BC. The Yelamu group of the Ohlone people resided in several small villages when a Spanish exploration party, led by Don Gaspar de Portolà arrived on November 2, 1769, the first documented European discovery of San Francisco Bay. Seven years later, on March 28, 1776 the Spanish established a fort, followed by a mission, Mission San Francisco de Asís (Mission Dolores).

Upon independence from Spain in 1821, the area became part of Mexico. In 1835, Englishman William Richardson erected the first significant homestead outside the immediate vicinity of the Mission Dolores, near a boat anchorage around what is today Portsmouth Square. Together with Mission Alcalde Francisco de Haro, he laid out a street plan for the expanded settlement, and the town, named Yerba Buena, began to attract American settlers. Commodore John D. Sloat claimed California for the United States on July 7, 1846, during the Mexican-American War, and Captain John B. Montgomery arrived to claim Yerba Buena two days later. Yerba Buena was renamed San Francisco the next year. Despite its attractive location as a port and naval base, San Francisco was still a small settlement with inhospitable geography.

The California Gold Rush brought a flood of treasure seekers. With their sourdough bread in tow, prospectors accumulated in San Francisco over rival Benicia, raising the population from 1,000 in 1848 to 25,000 by December 1849. The promise of fabulous riches 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. California was quickly granted statehood 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 1859, further drove rapid population growth. 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.

Entrepreneurs sought to capitalize on the wealth generated by the Gold Rush. Early winners were the banking industry, which saw the founding of Wells Fargo in 1852, and the railroad industry, as the magnates of the Big Four, led by Leland Stanford, collaborated in the building of the First Transcontinental Railroad. The development of the Port of San Francisco established the city as a center of 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 creating the city's Chinatown quarter. 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. By the turn of the century, San Francisco was a major city known for its flamboyant style, stately hotels, ostentatious mansions on Nob Hill, and a thriving arts scene.

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 would 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. More than three-quarters of the city lay in ruins, including almost all of the downtown core. Contemporary accounts reported that 498 people lost their lives, though modern estimates put the number in the several thousands. More than half the city's population of 400,000 were left homeless. 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.

Rebuilding was rapid and performed on a grand scale. Rejecting calls to completely remake the street grid, San Franciscans opted for speed. Amadeo Giannini's Bank of Italy, later to become Bank of America, provided loans for many of those whose livelihoods had been devastated. The destroyed mansions of Nob Hill became grand hotels. City Hall rose once again in splendorous Beaux Arts style, and the city celebrated its rebirth at the Panama-Pacific International Exposition in 1915.

In ensuing years, the city solidified its standing as a financial capital; in the wake of the 1929 stock market crash, not a single San Francisco-based bank failed. Indeed, it was at the height of the Great Depression that San Francisco undertook two great civil engineering projects, simultaneously constructing the San Francisco-Oakland Bay Bridge and the Golden Gate Bridge, completing them in 1936 and 1937 respectively. It was in this period that the island of Alcatraz, a former military stockade, began its service as a federal maximum security prison, housing notorious inmates such as Al Capone. San Francisco later celebrated its regained grandeur with a World's Fair, the Golden Gate International Exposition in 1939–40, creating Treasure Island in the middle of the bay to house it.

During World War II, the Hunters Point Naval Shipyard became a hub of activity and Fort Mason became the primary port of embarkation for service members shipping out to the Pacific theater of operations. The explosion of jobs drew many people, especially African Americans from the South, to the area. After the end of the war, many military personnel returning from service abroad and civilians who had originally come to work decided to stay. The UN Charter creating the United Nations was drafted and signed in San Francisco in 1945 and, in 1951, the Treaty of San Francisco officially ended the war with Japan.

Urban planning projects in the 1950s and 1960s saw widespread destruction and redevelopment of westside neighborhoods and the construction of new freeways, of which only a series of short segments were built before being halted by citizen-led opposition. The Transamerica Pyramid was completed in 1972, and in the 1980s the Manhattanization of San Francisco saw extensive high rise development downtown. Port activity moved to Oakland, the city began to lose industrial jobs, and San Francisco began to turn to tourism as the most important segment of its economy. 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.

Over this same period, San Francisco became a magnet for America's counterculture. Beat Generation writers fueled the San Francisco Renaissance and centered on the North Beach neighborhood in the 1950s. Hippies flocked to Haight-Ashbury in the 1960s, reaching a peak with the 1967 Summer of Love. In the 1970s, the city became a center of the gay rights movement, with the emergence of The Castro as an urban gay village, the election of Harvey Milk to the Board of Supervisors, and his assassination, along with that of Mayor George Moscone, in 1978.

The 1989 Loma Prieta earthquake caused destruction and loss of life throughout the Bay Area. In San Francisco, the quake severely damaged structures in the Marina and South of Market districts and precipitated the demolition of the damaged Embarcadero Freeway and much of the damaged Central Freeway, allowing the city to reclaim its historic downtown waterfront.

During the dot-com boom of the late 1990s, startup companies invigorated the economy. Large numbers of entrepreneurs and computer application developers moved into the city, followed by marketing and sales professionals that changed the social landscape as once poorer neighborhoods became gentrified. When the bubble burst in 2001, many of these companies folded and their employees left, although high technology and entrepreneurship continued to be mainstays of the San Francisco economy.