Han–Xiongnu War participant Han dynasty
The Han–Xiongnu War, also known as the Sino–Xiongnu War, was a series of military conflicts fought over two centuries (from 133 BC to 89 AD) between the Chinese Han Empire and the nomadic Xiongnu confederation, although extended conflicts can be traced back as early as 200 BC and ahead as late as 188 AD.
The Chinese civilization initially clashed with nomadic tribes that would later become the Xiongnu confederation during the Warring States period, and various northern states built elongated fortifications (which later became the Great Wall) to defend against raids from the Mongolian Plateau. The unified Qin dynasty, who conquered all other states under the First Emperor, dispatched General Meng Tian in 215 BC in a successful compaign to expel the Xiongnu from the Ordos region. However, the subsequent civil wars following Qin dynasty's collapse gave the Xiongnu tribes, who were then unified into a large confederacy under Modu Chanyu, the opportunity to reinvade the Ordos region.  After the Western Han dynasty was established in 202 BC, Emperor Gao tried to fight off Xiongnu invasions but had himself trapped in an ambush during the Battle of Baideng, and a truce was negotiated. Decades of de jure "peace" then ensued then followed with the Chinese gifting "marriage alliance" to appease the Xiongnu, who still raided Chinese borderlands routinely.
However, starting from the reign of the seventh Han ruler, Emperor Wu, the Han Empire began to change from a relatively passive foreign policy to a proactively offensive strategy seeking to permanently remove the northern threat. The tension fully escalated in 133 BC when the Han army unsuccessfully tried to ambush Xiongnu raiders at Mayi, and retaliatory raids intensified. Emperor Wu then started deploying newer generations of military commanders and launched several expeditions to control the Ordos Loop, Hexi Corridor and Western Regions, eventually pushing the Xiongnu north beyond the Gobi Desert with a decisive campaign in 119 BC. After the death of Emperor Wu in 87 BC, the war winded down to mostly smaller border conflicts, although Emperor Xuan and Yuan had each sanctioned major offensives against the Xiongnu during their reigns.  The overall strategic Han successes against the Xiongnu allowed the Chinese to project their influence deeply into Central Asia, which eventually led to the establishment of a regional protectorate in 60 BC. For the Xiongnu, the situation deteriorated with each setback, leading to erosion of the chanyu's prestige and dominance, and the subsequent internal power struggles further weakened the confederation, fracturing it into various self-ruling factions. Han Empire then began adhere to a divide and rule strategy, using marriage alliances (such as that of Wang Zhaojun to Huhanye) to recruit some against others.
During the interregnum Xin dynasty, Wuzhuliu chanyu waged war in 11 AD after Wang Mang, who usurped the Han throne, attempted to split the Xiongnu by instating 15 new chanyu. Wang Mang mobilized 300,000 troops against Xiongnu and forced Goguryeo, Wuhuan and various Western Regions city-states to send conscripts and provisions, which led to the mass defection of these vassal states. After the Eastern Han dynasty was established in 25 AD, the Chinese initially found their hands full after the chaotic civil war and could not afford any full-scale mobilizations against the Xiongnu raids, therefore resorted to continue lobbying among different Xiongnu faction rulers instead. This continued for another two decades until 46 AD, when repeated natural disasters severely weakened the Xiongnu and forced them to flee north from an attack by Wuhuan.  Xiongnu then permanently split in 48 AD into two groups, known as the Northern and Southern Xiongnu, respectively. The Southern Xiongnu eventually submitted to the Han Empire and became auxiliaries/mercenaries against the Northern Xiongnu, who continued to resist and was eventually evicted westwards by the further expeditions by the Han Empire and its vassals, as well as the rise of other hostile Donghu states like Xianbei. In 89 AD, General Dou Xian led 50,000 cavalries on an expedition that decisively defeated the Northern Xiongnu main force, causing it to split further. In 91 AD, Northern Chanyu was defeated in the Battle of the Altai Mountains, and the Northern Xiongnu fled west into Dzungaria, where they continued causing sporadic troubles until 151 AD when a 4,000-strong Han militia was enough to defeat them, causing them to flee further west into Central Asia and since disappeared from historical records. Southern Xiongnu, on the other hand, continued cycles of "rebel then resubmit" under the Eastern Han dynasty til as late as the Yellow Turban Rebellion, but from 89 AD onwards the Han Empire's main concern had already switched to the Qiang people, who had become an increasingly bigger headache than the Xiongnu.Background
During the Warring States period, the Qin, Zhao, and Yan states conquered various nomadic territories inhabited by the Xiongnu and other Hu peoples. They strengthened their new frontiers with elongated wall fortifications. By 221 BC, the Qin ended the chaotic Eastern Zhou period by conquering all other states and unifying China proper. In 215 BC, Qin Shi Huang ordered General Meng Tian to set out against the Xiongnu tribes, situated in the Ordos region, and establish a frontier region at the Ordos Loop. Believing that the Xiongnu were a possible threat, the emperor launched a pre-emptive strike against the Xiongnu with the intention of expanding his empire. Later that year (215 BC), General Meng Tian succeeded in defeating the Xiongnu and driving them from the Ordos region, seizing their territory as result. After the catastrophic defeat at the hands of Meng, Touman Chanyu and his followers fled far into the Mongolian Plateau. Fusu (Prince of Qin) and General Meng Tian were stationed at a garrison in Suide and soon began the construction of the walled defences, connecting them with the old walls built by Qin, Yan and Zhao states. The fortified walls ran from Liaodong to Lintao, thus enclosing the conquered Ordos region, safeguarding the Qin empire against the Xiongnu and other northern nomadic people. Due to the northward expansion, the threat that the Qin empire posed to the Xiongnu ultimately led to the state formation of the many tribes towards a confederacy.However, after the sudden death of Qin Shi Huang, the ensuing political corruption and chaos during the short reign of Qin Er Shi would lead to various anti-Qin rebellions, eventually bringing about the collapse of the Qin dynasty. A massive civil war then erupted between various reinstated states, with Liu Bang eventually victorious to establish the Han dynasty. During the transitional years between Qin and Han, while the Chinese were mainly focused towards the interior of their nation, the Xiongnu took the opportunity to retake the territory north of the wall. The Xiongnu frequently led incursions to the Han frontier and had considerable political influence over the border regions. In response, Emperor Gaozu led a Han army against the Xiongnu in 200 BC, pursuing them as far as Pingcheng (present-day Datong, Shanxi) before being ambushed by Modu Chanyu's cavalry. His encampment was encircled by the Xiongnu, but Emperor Gaozu escaped after seven days. After realizing that a military solution was not feasible for the time being, Emperor Gaozu sent Liu Jing to negotiate peace with Modu Chanyu. In 198 BC, a marriage alliance was concluded between the Han and the Xiongnu, but this proved far from effective as the incursions in the frontier regions continued.