Hanzhong (漢中) was a commandery and region in the Han River valley, between the Wei River (Guanzhong) and the Sichuan Basin. It lay in what is now southern Shaanxi. Control of Hanzhong determined who could move between the north-west and Yi Province.
Cao Cao took Hanzhong from Zhang Lu in 215. Liu Bei launched the Hanzhong Campaign (217–219), defeated Cao Cao’s forces at the Battle of Dingjunshan, and took the region. Hanzhong then became Shu Han’s northern frontier. Wei Yan was placed in charge of the defence; Zhuge Liang used it as a base for the Northern Expeditions. Ma Su and Zhuge Qiao served there. In 263, the Wei invasion that ended Shu (Wei Conquest of Shu) came through Hanzhong after capturing the passes.