During Qin dynasty, Shihuangdi sent Meng Tian, commanding 300,000 troops to defend his empire from Xiongnu's attacks.
They spent 10 years connecting the Great Wall of Yan, Qin and Zhao, thus building Great Wall of Qin, the first Great Wall of 10,000 li, its 80-kilometer-long relics currently located in Batou (坝头), or Erdaogou (二道沟) in local slang, to the north of Zhangjiakou downtown area.
The southern area of Zhangjiakou was under jurisdiction of Dai Commandery and Shanggu Commandery.

During Han dynasty, most part of the area belonged to You Prefecture while some parts belonged to Wuhuan, Xiongnu and Xianbei.
When Liu Bang established Han dynasty, he granted Dai and the title of King of Dai to his brother Liu Zhong in 201 BC.
One year later, Liu Zhong was defeated by Modu Chanyu of Xiongnu and escaped, thus demoted.
In 196 BC, Chen Xi, the chancellor of Zhao, rebelled against the emperor and occupied more than 20 cities soon after.
As a result, Liu Bang commanded an army in person from Luoyang.
During the war, the empress launched a coup d'état and killed Han Xin, the most important general who helped establish Han dynasty.
With the help of Fan Kuai and Zhou Bo, Liu Bang defeated Chen Xi very soon.
Following the rebellion, Liu Bang granted the title of King of Dai to his third son, Liu Heng, later Emperor Wen of Han.

Zhangjiakou was a major battleground during Han–Xiongnu War.
In 127 BC, Xiongnu cavalry attacked Shanggu (currently Huailai), Yuyang.
The Emperor Wu of Han launched a successful counterattack.
In 124 BC, Xiongnu cavalry invaded Dai Commandery.
Emperor Wu ordered Wei Qing commanding 100,000 troops to counterattack.
Wei Qing left the Great Wall more than 600 to 700 kilometers, encircled Xiongnu's head, Youxianwang (右贤王).
In 122 BC, 50,000 Xiongnu invaded Shanggu, killed hundreds of people.
In next March, Huo Qubing commanded 10,000 cavalry to counterattack and achieved success.
In 119 BC, Wei Qing and Huo Qubing each commanded 50,000 cavalry.
Huo Qubing departed from Dai Commandery, marched 2000 li northward crossing Gobi desert.
Finally, Han troops defeated Xiongnu under Yizhixie completely.
Following the success, a new office, the Colonel-Protector of the Wuhuan (护乌桓校尉), was established in Shanggu in order to prevent contact between the Wuhuan with the Xiongnu and to use them to monitor the Xiongnu activities.
In 106 BC, Emperor Wu of Han organized the Western Han Dynasty into 13 province-sized prefectures, each administered by a cishi (刺史) or inspector, thus putting Shanggu and Dai under the jurisdiction of You Prefecture.

Following Xin dynasty, Lu Fang (卢芳) rebelled against Han but was defeated.
Then, Emperor Guangwu of Han granted him the King of Dai.
In 48 AD, Eastern Han dynasty established Colonel-Protector of the Wuhuan in Ningcheng (宁城), Shanggu (currently, Ningyuanbao Qiaodong District), representing Han's management of Wuhuan.
Meanwhile, Han also opened Hu Market (胡市) to conduct regular exchanges with Wuhuan in Ningcheng.
From 110 AD, Ningcheng also began to manage affairs with Xianbei.
During Qin dynasty, Shihuangdi sent Meng Tian, commanding 300,000 troops to defend his empire from Xiongnu's attacks. They spent 10 years connecting the Great Wall of Yan, Qin and Zhao, thus building Great Wall of Qin, the first Great Wall of 10,000 li, its 80-kilometer-long relics currently located in Batou (坝头), or Erdaogou (二道沟) in local slang, to the north of Zhangjiakou downtown area. The southern area of Zhangjiakou was under jurisdiction of Dai Commandery and Shanggu Commandery.
During Han dynasty, most part of the area belonged to You Prefecture while some parts belonged to Wuhuan, Xiongnu and Xianbei. When Liu Bang established Han dynasty, he granted Dai and the title of King of Dai to his brother Liu Zhong in 201 BC. One year later, Liu Zhong was defeated by Modu Chanyu of Xiongnu and escaped, thus demoted. In 196 BC, Chen Xi, the chancellor of Zhao, rebelled against the emperor and occupied more than 20 cities soon after. As a result, Liu Bang commanded an army in person from Luoyang. During the war, the empress launched a coup d'état and killed Han Xin, the most important general who helped establish Han dynasty. With the help of Fan Kuai and Zhou Bo, Liu Bang defeated Chen Xi very soon. Following the rebellion, Liu Bang granted the title of King of Dai to his third son, Liu Heng, later Emperor Wen of Han.
Zhangjiakou was a major battleground during Han–Xiongnu War. In 127 BC, Xiongnu cavalry attacked Shanggu (currently Huailai), Yuyang. The Emperor Wu of Han launched a successful counterattack. In 124 BC, Xiongnu cavalry invaded Dai Commandery. Emperor Wu ordered Wei Qing commanding 100,000 troops to counterattack. Wei Qing left the Great Wall more than 600 to 700 kilometers, encircled Xiongnu's head, Youxianwang (右贤王). In 122 BC, 50,000 Xiongnu invaded Shanggu, killed hundreds of people. In next March, Huo Qubing commanded 10,000 cavalry to counterattack and achieved success. In 119 BC, Wei Qing and Huo Qubing each commanded 50,000 cavalry. Huo Qubing departed from Dai Commandery, marched 2000 li northward crossing Gobi desert. Finally, Han troops defeated Xiongnu under Yizhixie completely. Following the success, a new office, the Colonel-Protector of the Wuhuan (护乌桓校尉), was established in Shanggu in order to prevent contact between the Wuhuan with the Xiongnu and to use them to monitor the Xiongnu activities. In 106 BC, Emperor Wu of Han organized the Western Han Dynasty into 13 province-sized prefectures, each administered by a cishi (刺史) or inspector, thus putting Shanggu and Dai under the jurisdiction of You Prefecture.
Following Xin dynasty, Lu Fang (卢芳) rebelled against Han but was defeated. Then, Emperor Guangwu of Han granted him the King of Dai. In 48 AD, Eastern Han dynasty established Colonel-Protector of the Wuhuan in Ningcheng (宁城), Shanggu (currently, Ningyuanbao Qiaodong District), representing Han's management of Wuhuan. Meanwhile, Han also opened Hu Market (胡市) to conduct regular exchanges with Wuhuan in Ningcheng. From 110 AD, Ningcheng also began to manage affairs with Xianbei.
Zhangjiakou