During the Han-ruling period, Au Lac was divided into three provinces: Giao Chi, Cuu Chan and Nhat Nam. Hanoi belonged to Giao Chi but it was not mentioned in the history books of the first five centuries. In the middle of the fifth century (454-456), Hanoi was recorded as the center of Tong Binh District which later became a province.
Tong Binh province had three districts: Nghia Hoai, Tuy Ninh in the south of the Red River (present Tu Liem and Hoai Duc) and Xuong Quoc in the north of the river (Dong Anh and Gia Lam Districts). The seat of government of Tong Binh was in the urban area of present Hanoi.
In 544, Ly Bi led an insurrection and built a fortress by the To Lich River. After defeating the Liang invaders, he proclaimed himself King and established the Van Xuan Kingdom. He set up Khai Quoc (Nation Founding) Pagoda by the Red River, which was later shifted to West Lake and renamed Tran Quoc (Nation Defending) Pagoda. Thereafter, his nephew, Ly Phat Tu moved the capital to Co Loa, where he ruled until 602 and was defeated by the Chinese Sui.
Chinese rulers of the Tang Dynasty (618-907) replaced the Sui Dynasty to rule Van Xuan. They renamed Vietnam An Nam (Pacified South) which comprised 12 provinces and 50 districts (671), and had Tong Binh (present-day Hanoi) as its capital. Around the middle of the Tang Dynasty, Tong Binh had a new name: Dai La, as Gao Pen built Dai La Citadel there in 866.
But the Pacified South could no longer be really pacified. Phung Hung (766-779) led an uprising and successfully liberated Tong Binh. Following it another insurrection broke out let by Duong Thanh (819-820). Thereafter, the Khuc family (Khuc Thua Du, Khuc Hao, Khuc Thua My) rose up from 905 to 930, to drive out the Chinese authorities and to administer An Nam.
In 938, Chinese troops of the South Han Dynasty waged a war of aggression on Vietnam but were defeated by Ngo Quyen who, thereafter, proclaimed himself king and established his capital in Co Loa. After one thousand years, Co Loa again became the capital of Vietnam.