In 1221, Vienna received the rights of a city and as a staple port (Stapelrecht). This meant that all traders passing through Vienna had to offer their goods in the city. This allowed the Viennese to act as middlemen in trade, so that Vienna soon created a network of far-reaching trade relations, particularly along the Danube basin and to Venice, and to become one of the most important cities in the Holy Roman Empire.
In 1529, Vienna was besieged by the Ottoman Turks for the first time (the First Turkish Siege), although unsuccessfully. The city, protected by medieval walls, only barely withstood the attacks, until epidemics and an early winter forced the Turks to retreat. The siege had shown that new fortifications were needed. Following plans by Sebastian Schrantz, Vienna was expanded to a fortress in 1548.
In 1921, Vienna was separated from the surrounding Lower Austria and became a state of its own. The left-wing Social Democrats, who had dominated since the end of the war, were now in charge of the city administration. "Red Vienna" was considered an international model. Many notable Gemeindebauten (low-cost residential estates) were built during that period.
On May 15, 1955, the country regained its political independence and sovereignty with the "Austrian State Treaty". The Austrian Parliament immediately amended the treaty to establish Austria's future neutrality and non-alignment (similar to that of Switzerland). This peace treaty was called a state treaty because Austria had temporarily ceased to exist in 1938.
Vienna was the capital of the surrounding Bundesland of Lower Austria (German: Niederösterreich) until 1986, when it was replaced by Sankt Pölten. As Vienna was not a geographical part of Lower Austria it was a capital outside of the territory it served.