In the Sixteen Kingdoms period, the Tuoba family of the Xianbei were the rulers of the state of Dai (Sixteen Kingdoms). Although it was conquered by the Former Qin, the defeat of the Former Qin at the Battle of Fei River resulted in the collapse of the Former Qin. The grandson of the last prince of Dai Tuoba Shiyijian, Tuoba Gui restored the fortunes of the Tuoba clan, renaming his state Wei (now known as Northern Wei) with its capital at Shengle (near modern Hohhot). Under the rule of Emperors Daowu (Tuoba Gui), Mingyuan, and Taiwu, the Northern Wei progressively expanded. The establishment of the early Northern Wei state and economy was also greatly indebted to the father-son pair of Cui Hong and Cui Hao. Tuoba Gui engaged in numerous conflicts with the Later Yan that ended favorably for the Northern Wei after they received help from Zhang Gun that allowed them to destroy the Later Yan army at the Battle of Canhe Slope. Following this victory, Tuoba Gui conquered the Later Yan capital of Pingcheng (modern day Datong). That same year he declared himself as Emperor Daowu.
Due to Emperor Daowu’s cruelty, he was killed by his son Tuoba Shao, but crown prince Tuoba Si managed to defeat Tuoba Shao and took the throne as Emperor Mingyuan. Though he managed to conquer Liu Song’s province of Henan, he died soon afterwards. Emperor Mingyuan’s son Tuoba Tao took the throne as Emperor Taiwu. Due to Emperor Taiwu’s energetic efforts, Northern Wei’s strength greatly increased, allowing them to repeatedly attack Liu Song. After dealing the Rouran threat to his northern flank, he engaged in a war to unite northern China. With the fall of the Northern Liang in 439, Emperor Taiwu united northern China, ending the Sixteen Kingdoms period and beginning the Northern and Southern dynasties period with their southern rivals, the Liu Song.
Even though it was a time of great military strength for the Northern Wei, because of Rouran harassment in the north, they could not fully focus on their southern expeditions. After uniting the north, Emperor Taiwu also conquered the strong Shanshan kingdom and subjugated the other kingdoms of Xiyu, or the Western Regions. In 450, Emperor Taiwu once again attacked the Liu Song and reached Guabu (瓜步, in modern Nanjing, Jiangsu), threatening to cross the river to attack Jiankang, the Liu Song capital. Though up to this point, the Northern Wei military forces dominated the Liu Song forces, they took heavy casualties. The Northern Wei forces plundered numerous households before returning north.
At this point, followers of the Buddhist Gai Wu (蓋吳) rebelled. After pacifying this rebellion, Emperor Taiwu, under the advice of his Daoist prime minister Cui Hao, proscribed Buddhism, in the first of the Three Disasters of Wu. At this late stage in his life, Emperor Taiwu meted out cruel punishments, which led to his death in 452 at the hands of the eunuch Zong Ai. This sparked off turmoil that only ended with the ascension of Emperor Wencheng later that same year.
In the first half of the Northern Wei dynasty (386–534), the Xianbei steppe tribesmen who dominated northern China kept a policy of strict social distinction between them and their Chinese subjects. Chinese were drafted into the bureaucracy, employed as officials to collect taxes, etc. However, the Chinese were kept out of many higher positions of power. They also represented the minority of the populace where centers of power were located.
Widespread social and cultural transformation in northern China came with Emperor Xiaowen of Northern Wei (reigned 471–499), whose father was a Xianbei, but whose mother was Chinese. Although of the Tuoba Clan from the Xianbei tribe, Emperor Xiaowen asserted his dual Xianbei-Chinese identity, renaming his own clan after the Chinese Yuan (元 meaning “elemental” or “origin”). In the year 493 Emperor Xiaowen instituted a new sinification program that had the Xianbei elites conform to many Chinese standards. These social reforms included donning Chinese clothing (banning Xianbei clothing at court), learning the Chinese language (if under the age of thirty), applied one-character Chinese surnames to Xianbei families, and encouraged the clans of high-ranking Xianbei and Chinese families to intermarry. Emperor Xiaowen also moved the capital city from Pingcheng to one of China’s old imperial sites, Luoyang, which had been the capital during the earlier Eastern Han and Western Jin dynasties. The new capital at Luoyang was revived and transformed, with roughly 150,000 Xianbei and other northern warriors moved from north to south to fill new ranks for the capital by the year 495. Within a couple decades, the population rose to about half a million residents, and was famed for being home to over a thousand Buddhist temples. Defectors from the south, such as Wang Su of the prestigious Langye Wang family, were largely accommodated and felt at home with the establishment of their own Wu quarter in Luoyang (this quarter of the city was home to over three thousand families). They were even served tea (by this time gaining popularity in southern China) at court instead of yogurt drinks commonly found in the north.
In the year 523, Prince Dongyang of the Northern Wei was sent to Dunhuang to serve as its governor for a term of fifteen years. With the religious force of Buddhism gaining mainstream acceptance in Chinese society, Prince Dongyang and local wealthy families set out to establish a monumental project in honor of Buddhism, carving and decorating Cave 285 of the Mogao Caves with beautiful statues and murals. This promotion of the arts would continue for centuries at Dunhuang, and is now one of China’s greatest tourist attractions.
In that same year of 523 a revolt of several military garrisons was caused by a food shortage far north of Luoyang. After this was suppressed, the government had 200,000 surrendered garrison rebels deployed to Hebei, which proved later to be a mistake when a former garrison officer organized another rebellion in the years 526–527. The Wei court was betrayed by one of their own generals, who had the empress dowager and the young emperor thrown into the Yellow River, while establishing his own puppet ruler to maintain authority. As conflict swelled in the north between successive leaders, Gao Huan took control of the east and Luoyang (holding Emperor Xiaojing of Eastern Wei as a puppet ruler) by 534, while his rival Yuwen Tai took control of the west and the traditional Chinese capital of Chang’an by 535. Eventually, Gao Huan’s son Gao Yang forced the Eastern Wei emperor to abdicate in favor of his claim to the throne, establishing the Northern Qi dynasty (551–577). Afterwards, Yuwen Tai’s son Yuwen Jue seized the throne of power from Emperor Gong of Western Wei, establishing the Northern Zhou dynasty (557–580). The Northern Zhou dynasty was able to defeat and conquer Northern Qi in 577, reunifying the north. However, this success was short-lived, as the Northern Zhou was overthrown in 581 by Yang Jian, who became Emperor Wen of Sui. With greater military power and morale, along with convincing propaganda that the Chen dynasty ruler Chen Shubao was a decadent ruler who had lost the Mandate of Heaven, the Sui Dynasty was able to effectively conquer the south. After this conquest, the whole of China entered a new golden age of reunification under the centralization of the short-lived Sui dynasty and succeeding Tang dynasty (618–907).