He was the son of a Colombian doctor, Manuel Ignacio Carvajal, and his wife María del Pilar Ambulodegui. He studied at the College of Our Lady of Guadalupe in Lima, and entered the Naval College in 1860, where he graduated as an Officer Cadet in 1863. He remained there as a professor of arithmetic and geography and, the following year, he was awarded the rank of Ensign. He joined Colonel Mariano Ignacio Prado's coup and fought at the Battle of Callao, after which he was promoted to First Lieutenant.