When the Holy Roman Empire ended on August 6th, 1806, Hamburg became a souvereign state with the title Free Hanzecity. In 1810 however, this state was incorporated in the French Empire.
When the French military left the city on May 30th, 1814, the local authorities took over control and after the Viennese Congres, Hamburg became an independent state within the German Federation. In 1819, the title Free Hanzecity (Freie und Hanzestadt Hamburg) was bestowed upon the city.
The formal indendency ended on March 31st, 1868 as the city joined the North-German Federation, effectively placing the city under Prussian rule. Yet Hamburg retained its position as Free Hanzecity. Within the present Federal Republic of Germany, Hamburg is an official Bundesland.