Zhang Ni was from Nanchong County(南充縣), Ba Commandery 巴郡), which is present-day Nanchong, Sichuan. He started his career around the age of 19 as an Officer of Merit (功曹) in the local county office. In 214, when the warlord Liu Bei seized control of Yi Province (covering present-day Sichuan and Chongqing) from its provincial governor Liu Zhang, some bandits used the opportunity to raid the county office. During the ensuing chaos, Zhang Ni engaged the bandits in close combat and protected the county magistrate's wife. He became famous for his courageous actions and was later summoned to the commander's office to serve as an Assistant Officer(從事). Around this time, two scholars Gong Lu and Yao Zhou were appointed with a very important salary within the same prefecture as Ni. Lu and Zhou at the time enjoyed a good reputation and some fame, however both of them heard of Zhang Ni's accomplishment hence they respected him and became friends with him.