Before Stockholm, the towns that mattered on Lake Mälaren were Birka, a Viking trading post, and later Sigtuna. When pirates sacked Sigtuna in 1187, the strait into the lake needed defending. Logs driven into that channel, dated to around the year 1000, probably gave the city its name: stock means log, holm means islet. Stockholm first appears in letters from Birger Jarl and King Valdemar in 1252, and German merchants he invited helped found the city.
Under the Kalmar Union, from 1397 to 1523, whoever held Stockholm held the kingdom, and Swedish and Danish factions besieged it again and again. In 1520 the Danish king Christian II took the city and had leading nobles and burghers beheaded: the Stockholm Bloodbath. Gustav Vasa won it back three years later and found every second building abandoned. With the Reformation, sermons switched to Swedish in 1525, and the German and Finnish parishes set up in the 1530s still exist. The German Church is one of Gamla stan's notable buildings.
In the 17th century Sweden became a great power, and Stockholm was made its official capital in 1634. The empire nearly ringed the Baltic. Between 1610 and 1680 the population grew sixfold, and planners laid wide, straight streets across the ridges of Norrmalm, Östermalm, Kungsholmen and Södermalm. Many of those streets are the ones you walk today. After a fire in 1625, Stora Nygatan and Lilla Nygatan were cut through the old town, and a row of palaces replaced the medieval wall along Skeppsbron.
Then it went wrong. Plague killed about 20,000 people in 1710, more than a third of the city, and after the Great Northern War the city stagnated. Gustav III, a king who loved the arts, opened the Royal Opera on his new square, Gustav Adolfs torg, in 1782. He was assassinated in Norrmalm ten years later. Carl Michael Bellman's comic songs about the taverns and characters of this city are still popular.
Losing Finland in 1809 left Stockholm poor and off-centre for decades; by 1850 widows outnumbered widowers six to one. Then the railway arrived, Central Station opened in 1871, and Albert Lindhagen's 1866 plan gave the city broad esplanades such as Sveavägen, 70 metres wide. In the 1880s alone, more than 2,000 buildings went up and the population jumped from 168,000 to 245,000. Luxury housing on Strandvägen is part of this boom.
Sweden was largely untouched by both world wars, so the city still has buildings from every century since the 1400s. Its own planners did more damage. From 1955 to 1975 the city tore down hundreds of Norrmalm's old buildings, much of the Klara district among them, to make way for the concrete of Sergels torg. Ragnar Östberg's City Hall, finished in 1923, came out better, and the 1950s suburb of Vällingby became a model for other cities.