The Danube Valley has been inhabited for thousands of years, as evidenced in the 1906 discovery of the 25,000-year-old fertility statuette known as the Venus of Willendorf. Celtic settlements had been established in the vicinity some 500 years before the Romans turned up around AD 9 to construct a military camp called Vindobona. The fort was built smack bang in the middle of today's Innere Stadt, within a square bordered by Graben, Tiefer Graben, Ruprechtskirche and Rotenturmstrasse. The Romans withdrew in the early 5th century, leaving the strategic east-west crossroads to be fought over by successive waves of migrating tribes and armies.
The Frankish king Charlemagne entered the picture in 803, establishing an eastern outpost in the Danube Valley west of Vienna known as the Ostmark. Vienna was first documented as a city in 1137, when it was ruled by the Bavarian Babenberg dukes. The death of the last Babenberg ruler at the hands of invading Hungarian forces ushered in a turbulent interregnum of almost 40 years before matters were settled by the new Holy Roman Emperor, Rudolf of Habsburg. Rudolf granted his two sons the fiefdoms of Austria and Styria in 1282, and one of the most powerful dynasties in history was born.
A succession of energetic, empire-building Habsburgs saw the dynasty extend its dominion over Carinthia, Carniola and Tirol. Vienna became a bishopric, the Habsburgs became archdukes and a succession of politically motivated marriages turned the dynasty into an empire, adding territories like Burgundy, the Netherlands and Spain. The empire was soon too vast to be ruled by one person, and in 1521 it was split between the two princely brothers Ferdinand (who was given Austria) and Charles (who grabbed everything else).
In the 16th- and 17th-centuries, Vienna faced several external threats to its security. The biggest danger was posed by Suleiman the Magnificent and his marauding Turks, who famously besieged the city for 18 days in 1528, destroying the outer districts. However, Ferdinand I sent Vienna's prestige soaring through the roof by moving his court to the city in 1533 as a protective measure. Plague killed an estimated 80,000 Viennese in 1679, and in 1683 the Turks returned to besiege the city once again - reputedly bringing a strange brew called coffee with them. The removal of the Turks by a combined force of German and Polish soldiers resulted in a triumphant frenzy of building in Vienna, giving the city its famous baroque face.
A string of profligate rulers culminated in the golden era of Maria Theresa and her son Joseph II, a period which saw the erection of palaces such as Schönbrunn and the Belvedere. Vienna's reputation as a centre for music was established during this time, with Mozart, Haydn, Beethoven and Schubert calling the city home. The Imperial nose was severely put out of joint by the Napoleonic occupations of 1805 and 1809: the Habsburg emperor was forced to give up the German crown and title of Holy Roman Emperor, and the battle with Napoleon left Vienna precariously poised on the brink of bankruptcy. The capital regained some of its pride with the Congress of Vienna in 1814-15. The disenfranchised general populace joined in the revolutions of 1848, and when order was restored the city had a new, 18-year-old emperor, Franz Josef I.
Under Franz Josef's lengthy rule, the Ringstrasse developments went up around the Innere Stadt. The city benefited from being at the helm of the new dual Austro-Hungarian monarchy, attracting a hugely varied émigré populace. Vienna's famed coffee houses became a hotbed of wildly opposing political and creative ideas. The city was graced by the artworks of the Viennese Secession, Jugendstil and Expressionist movements, adding names like Klimt, Schiele, Kokoschka, Moser, Mahler and the Wiener Werkstätte to the city's pantheon of big achievers.