Cao Pi was born in Qiao County in You Province to Cao Cao and Empress Bian, the heir apparent of Cao Cao. His brothers were Cao Ang, Cao Zhang, Cao Zhi, Cao Xiong, and others. Cao Pi first saw action in his father's campaign against Yuan Shao, and he gained a wife in Zhen Ji, who was formerly the wife of Yuan Xi. He also took part in the Battle of He Bei in 204 AD, and swatted the remnants of Yuan Shao's Army in the first decade of the 200s AD. Cao Pi next saw action at the Battle of Chi Bi and fought alongside his father in many of his wars in the Southlands. In 219 AD, Cao Pi was defeated by Zhao Yun and Huang Zhong, two of Liu Bei's generals, at the Battle of Han River, in the Hanzhong Campaign.
When his father died in 220 AD, Cao Pi overthrew the last nominal Han Emperor and founded the Kingdom of Cao Wei, declaring himself Emperor of Wei and choosing Chang'an as his capital, with Xuchang and Luoyang as other major cities. In 220 AD, the Eastern Wu reduced He Fei Castle, Cao Cao's legacy, to rubble, and Cao Pi was wounded. In 222 AD, an invasion of Wu failed at the Battle of Dongkou and the Second Battle of Ruxukou, and Cao Pi died in 226 AD, after having incited a Nanman rebellion against Shu.