An ammonia (NH3) sensor with high sensitivity based on indium-doped cerium oxide (In/CeO2) was prepared by hydrothermal method, and its sensing mechanism was revealed by first-principles. Experimental results show that indium ion (In3+) doping can effectually increase the sensitivity of NH3 sensor based on CeO2, which is mainly attributed to the enhancement in the number of oxygen vacancies and oxygen free radicals on the surface of In/CeO2. In/CeO2 sensor for NH3 with a response value of 5412.93 at a concentration of 1000 ppm, which is 65 times that of CeO2 sensor. Moreover, the low detection limit (LOD) of In/CeO2 is 0.433 ppm and its response/recovery time to 5 ppm NH3 is 1.1 s/1.4 s. Furthermore, the density functional theory (DFT) calculation confirmed that NH3 has higher adsorption-induced charge transfer and adsorption energy on the surface of In/CeO2 than other gases. This makes it easier for In/CeO2 to adsorb NH3 molecules and release more conduction electrons, thus improving the performance of In/CeO2. In addition, In/CeO2 sensor can be effectively used to detect the freshness of tofu through the concentration of NH3 released by the tofu in different storage environments. This work is beneficial to the safety monitoring of high protein food.