Xiongnu
Full-scale war broke out in autumn 129 BC, when 40,000 Chinese cavalry made a surprise attack on the Xiongnu at the border markets. In 127 BC, the Han general Wei Qing retook the Ordos. In 121 BC, the Xiongnu suffered another setback when Huo Qubing led a force of light cavalry westward out of Longxi and within six days fought his way through five Xiongnu kingdoms. The Xiongnu Hunye king was forced to surrender with 40,000 men. In 119 BC both Huo and Wei, each leading 50,000 cavalrymen and 100,000 footsoldiers (in order to keep up with the mobility of the Xiongnu, many of the non-cavalry Han soldiers were mobile infantrymen who traveled on horseback but fought on foot), and advancing along different routes, forced the "chanyu" and his court to flee north of the Gobi Desert. Major logistical difficulties limited the duration and long-term continuation of these campaigns. According to the analysis of Yan You (嚴尤), the difficulties were twofold. Firstly there was the problem of supplying food across long distances. Secondly, the weather in the northern Xiongnu lands was difficult for Han soldiers, who could never carry enough fuel. According to official reports, the Xiongnu lost 80,000 to 90,000 men, and out of the 140,000 horses the Han forces had brought into the desert, fewer than 30,000 returned to China.
Han–Xiongnu War
During the Warring States period, the Qin, Zhao, and Yan states conquered various nomadic territories inhabited by the Xiongnu and other Hu peoples. They strengthen 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 the entire nation. 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 to expand 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 with the construction of the walled defenses, connecting it 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.