Hanoi (Hà Nội) has been inhabited since at least 3000 BC. One of the first known permanent settlements is the Cổ Loa citadel founded around 200 BC.
Hanoi has had many names throughout history, such as Tống Bình and later Long Đỗ . In 866, it was turned into a citadel and was named Đại La.
Emperor Lý Thái Tổ made Thăng Long (today Hanoi) the capital city in the 11th century
In 1010, Lý Thái Tổ, the first ruler of the Lý Dynasty, moved the capital of Đại Việt to the site of the Đại La Citadel. Claiming to have seen a dragon ascending the Red River, he renamed it Thăng Long (Flying up dragon) - a name still used poetically to this day. It remained the capital of Vietnam until 1397, when the capital was moved to Thanh Hóa, also known as Tây Đô (English: Western Capital). Thăng Long then became Đông Đô (English: Eastern Capital).
In 1408, Chinese Ming Dynasty attacked and occupied Vietnam, then they renamed Đông Đô as Đông Quan (Eastern Gateway). In 1428, the Vietnamese overthrew the Chinese under the leadership of Lê Lợi, who later founded the Lê Dynasty and renamed Đông Quan as Đông Kinh (Eastern Capital, now called Tonkin in English). Right after the end of Tây Sơn Dynasty, it was named Bắc Thành (Northern Citadel).
In 1802, when the Nguyễn Dynasty was established and then moved the capital down to Huế. In 1831 the Nguyễn emperor, Minh Mạng renamed it "Hà Nội" . Hanoi was occupied by the French in 1873 and passed to them ten years later. It became the capital of French Indochina after 1887.
The city was occupied by the Japanese in 1940, and liberated in 1945, when it briefly became the seat of the Viet Minh government after Ho Chi Minh proclaimed the independence of Vietnam. But the French came back and reoccupied the city in 1946. After nine years of fighting between the French and Viet Minh forces, Hanoi became the capital of an independent North Vietnam in 1954, and the capital of Vietnam after April 30th 1975.