Hamburg, now officially the Free and Hanseatic City of Hamburg (German: Freie und Hansestadt Hamburg), is the second-largest city in Germany after Berlin and seventh largest city in the European Union.
The name Hamburg comes from the first permanent building on the site, a castle which the Emperor Charlemagne ordered constructed in AD 808. In 1189, by imperial charter, Frederick I "Barbarossa" granted Hamburg the status of a Free Imperial City of the Holy Roman Empire, and tax-free access (or free-trade zone) up the Lower Elbe into the North Sea. In 1265, an allegedly forged letter was presented to or by the Rath of Hamburg. This charter, along with Hamburg's proximity to the main trade routes of the North Sea and Baltic Sea, quickly made it a major port in Northern Europe. Its trade alliance with Lübeck in 1241 marks the origin and core of the powerful Hanseatic League of trading cities. On 8 November 1266, a contract between Henry III and Hamburg's traders allowed them to establish a hanse in London. This was the first time in history that the word hanse was used for the trading guild of the Hanseatic League. In 1270, the solicitor of the senate of Hamburg, Jordan von Boitzenburg, wrote the first description of civil, criminal and procedural law for a city in Germany in the German language, the Ordeelbook (Ordeel: sentence). On 10 August 1410, civil unrest forced a compromise (German: Rezeß, literally meaning: withdrawal). This is considered the first constitution of Hamburg.
Upon the dissolution of the Holy Roman Empire in 1806, the Free Imperial City of Hamburg was not incorporated into a larger administrative area while retaining special privileges (mediatised), but became a sovereign state with the official title of the Free and Hanseatic City of Hamburg. Hamburg was briefly annexed by Napoleon I to the First French Empire (1804-1814/1815). Russian forces under General Bennigsen finally freed the city in 1814. Hamburg re-assumed its pre-1811 status as a city-state in 1814. The Vienna Congress of 1815 confirmed Hamburg's independence and it became one of 39 sovereign states of the German Confederation (1815–1866).