The site of Tallinn is thought to have been settled by Finno-Ugric people around 2500 BC. There was probably an Estonian trading settlement here from around the 9th century AD, and a wooden stronghold was built on Toompea (tom-pe-ah; the hill dominating Tallinn) in the 11th century. The Danes under King Waldemar II (who conquered Northern Estonia in 1219) met tough resistance at Tallinn and were on the verge of retreat when a red flag with a white cross fell from the sky into their bishop's hands. Taking this as a sign of God's support, they went on to win the battle; the flag became their national flag. The Danes set their own castle on Toompea. The origin of the name Tallinn is thought to be from Taani linn, Estonian for 'Danish town'.
The Knights of the Sword took Tallinn from the Danes in 1227 and built the first stone fort on Toompea. German traders arrived from Visby on the Baltic island of Gotland and founded a colony of about 200 beneath the fortress. In 1238 Tallinn returned to Danish control, but in 1285 it joined the German-dominated Hanseatic League as a channel for trade between Novgorod, Pihkva (Russian: Pskov) and the west. Furs, honey, leather and seal fat moved west; salt, cloth, herring and wine went east.
By the mid-14th century, when the Danes sold Northern Estonia to the Teutonic Order, Tallinn was a major Hanseatic town with about 4000 people. A conflict of interest with the knights and bishop on Toompea led the mainly German artisans and merchants in the Lower Town to build a fortified wall to separate themselves from Toompea. However, Tallinn still prospered and became one of northern Europe's biggest towns. Tallinn's German name, Reval, coexisted with the local name until 1918.
Prosperity faded in the 16th century. The Hanseatic League had weakened, and Russians, Swedes, Danes, Poles and Lithuanians fought over the Baltic region. Tallinn survived a 29-week siege by Russia's Ivan the Terrible between 1570 and 1571. It was held by Sweden from 1561 to 1710, when, decimated by plague, Tallinn surrendered to Russia's Peter the Great.
In 1870 a railway was completed from St Petersburg, and Tallinn became a chief port of the Russian Empire. Freed peasants converged on the city from the countryside, increasing the percentage of Estonians in its population from 52% in 1867 to 89% in 1897. By WWI Tallinn had big shipyards and a large working class of over 100, 000.
Tallinn suffered badly in WWII, with thousands of buildings destroyed during Soviet bombing in 1944. After the war, under Soviet control, large-scale industry was developed in Tallinn - including the USSR's biggest grain-handling port - and the city expanded, its population growing to nearly 500, 000 from a 1937 level of 175, 000. Much of the new population came from Russia, and new high-rise suburbs were built on the outskirts to house the workers.
Not surprisingly, the days of Soviet occupation (1940-91) were hard on the capital. The explosion of Soviet-style settlements in the suburbs meant a loss of cultural life in the centre. Old Town by the 1980s was run-down, with most people preferring to live in the suburbs rather than the centre. Old Town began to be renovated in the late '80s, with independence largely playing out on the streets of Tallinn.
The 1990s saw the city transformed into a contemporary midsized city, with a beautifully restored Old Town and a modern business district. Today a look around the centre indicates that the city is booming. Cranes all around town show that building is underway. Some of the more recent projects include the shiny glass Viru Centre mall, which opened in 2004. Tallinn shows a taste for all things new, extending to IT-driven business at the fore of the new economy, and an Internet-savvy populace that makes other parts of the world seem outmoded. Internet banking and paying parking tickets online are just a few of the conveniences Tallinnese wouldn't do without.
In addition to increasing arrivals by ferry -and close ties to Finland - there's a newly renovated airport, wiping out gloomy vestiges of the Soviet past. Discount airlines carry passengers from Western Europe, which has contributed to Tallinn's reputation as a weekend party getaway.
Meanwhile, the outskirts of the city have yet to get the face-lift that the centre has received. In these parts of the city that few tourists see, you'll find poverty, unemployment and less infrastructure.