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
In 25 AD, Liu Xiu was established as Emperor Guangwu, restoring the Han throne after a usurpation by the Han official Wang Mang, thus initiating the Eastern Han period. During his reign, the Han empire began to abandon its offensive strategy against the Xiongnu, which allowed the latter to frequently raid the northern frontier. It resulted in large migrations southwards, which led to the depopulation of the frontier regions. During the Eastern Han period, various nomadic peoples were resettled in these frontier regions, serving the Han empire as cavalry against the Xiongnu. With his primary focus still towards the interior of the empire, Emperor Guangwu declined several requests from the western states to reestablish the office of Protector-General of the Western Regions. Early in Emperor Guangwu's reign, King Kang of Yarkand united neighboring kingdoms to resist the Xiongnu. At the same time, he protected the Han officials and people of the former Protector-General, who were still left behind after Wang Mang's reign. In 61 AD, Yarkand was conquered by Khotan and the western states fell in conflict with each other. Taking this opportunity, the Northern Xiongnu recovered their control over the Western Regions, which threatened the security of the Hexi Corridor. In 73 AD, General Dou Gu was sent on a punitive expedition to the Xiongnu and inflicted them a considerable defeat. Immediately, the fertile lands of Hami (Yiwu) was reoccupied and an agricultural garrison established. The next year (74 AD), he expelled the Xiongnu from Turfan and reoccupied the state. The recovery of Hami and Turfan facilitated the reestablishment of the Protector-General, since these important locations were key points to control the Western Regions.