Xiongnu
Sinologist Edwin Pulleyblank argued that the Xiongnu were part of a Xirong group called Yiqu, who had lived in Shaanbei and had been influenced by China for centuries, before they were driven out by the Qin dynasty. Qin's campaign against the Xiongnu expanded Qin's territory at the expense of the Xiongnu. In 215 BC, Qin Shi Huang sent General Meng Tian to conquer the Xiongnu and drive them from the Ordos Loop, which he did later that year. After the catastrophic defeat at the hands of Meng Tian, the Xiongnu leader Touman was forced to flee far into the Mongolian Plateau. The Qin empire became a threat to the Xiongnu, which ultimately led to the reorganization of the many tribes into a confederacy.In 209 BC, three years before the founding of Han China, the Xiongnu were brought together in a powerful confederation under a new chanyu, Modu Chanyu. This new political unity transformed them into a more formidable state by enabling formation of larger armies and the ability to exercise better strategic coordination. The Xiongnu adopted many of the Chinese agriculture techniques such as slave labor for heavy labor, wore silk like the Chinese, and lived in Chinese-style homes. The reason for creating the confederation remains unclear. Suggestions include the need for a stronger state to deal with the Qin unification of China that resulted in a loss of the Ordos region at the hands of Meng Tian or the political crisis that overtook the Xiongnu in 215 BC when Qin armies evicted them from their pastures on the Yellow River.
Han–Xiongnu War
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 bring 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.