Pei was born in a family of officials who served in the Eastern Jin government. His grandfather, Pei Mei, served as a Household Counsellor while his father, Pei Gui, was a zheng yuanwailang. Pei was fond of reading since his childhood, and he was already very familiar with classic texts such as the Analects of Confucius and the Classic of Poetry at the age of eight. In 391, during the reign of Emperor Xiaowu, Pei became a Palace General at the age of 20. In 398, during the reign of Emperor An, Pei's uncle, Yu Kai, who was the Governor of Yu Province, allied with Wang Gong, the Governor of Yan and Qing provinces, to attack the imperial capital, Jiankang. They were defeated. Yu Kai fled to join the warlordHuan Xuan, after which he nominated Pei to be the Administrator of Xinye, but Pei considered the dangers of joining his uncle and refused to move there. War broke out between the warlords later and Yu Kai was killed by Huan Xuan. Pei survived because he did not join Yu Kai. In the early fifth century, Pei served as a Regular Mounted Attendant and later as the prefect of Guzhang County. He was recalled to the imperial court later and was promoted to shangshu ci bu lang. In 416, the Jin imperial court ordered Liu Yu, the Duke of Song, to lead a campaign against the state of Later Qin. Pei was serving as a registrar then when he was ordered to join Liu Yu's army. Liu Yu was very impressed with Pei and praised him as a talented person, and then appointed him as zhizhong congshi shi. After Liu Yu's forces occupied Luoyang, Liu Yu appointed Pei as a xianma to assist the heir apparent of his dukedom. Liu Yu usurped the throne in 420 and ended the Eastern Jin dynasty. He founded the Liu Song dynasty and became historically known as "Emperor Wu of Liu Song". Pei took up various appointments in the Liu Song government, including Secretary of the Interior of Lingling, State Academician and rongcong puye. In 426, Emperor Wu's successor, Emperor Wen, sent officials to inspect the various provinces. Pei was sent to inspect Xiangzhou. After returning from his trip, Pei drafted 24 clauses based on his observations. He was promoted to Palace Gentleman Writer and Grand Judge of Si and Ji provinces, and was enfeoffed as the Marquis of Xi District. In his later years, Pei served as the Administrator of Yongjia, tongzhi sanqi changshi, and Administrator of South Langya. Pei retired from service at the age of 65 in 437. However, not long later, he was recalled back to the imperial court, and he served as Attendant Counsellor, State Academician, and Palace Counsellor. He died of illness at the age of 80 in 451.
Works
of the Liu Song dynasty felt that the historical text Records of the Three Kingdoms, written by Chen Shou in the third century, was too brief, so he commissioned Pei to make annotations to the text. Pei collected various sources, including those previously rejected by Chen Shou, and added them to the Sanguozhi, while making annotations and adding his personal commentary as well. His commentary, completed in 429, became integral to later editions of the Sanguozhi, making the joint work three times as long as the original. Emperor Wen praised his work as "immortal". Apart from making annotations to the Sanguozhi, Pei also wrote other books such as the Jin Ji, Pei Shi Jiazhuan, and Ji Zhu Sang Fu Jing Zhuan.