Miles was born in Maryland. He graduated from the United States Military Academy in 1824 and was commissioned a brevet second lieutenant in the 4th U.S. Infantry regiment, but was transferred immediately to the 7th U.S. Infantry Regiment, with which he served until 1847. He served on the western frontier and became adjutant of the 7th U.S. He was promoted to captain on June 8, 1836, and fought in the Seminole Wars in Florida from 1839 to 1842. At the start of the Mexican–American War, he received a brevet promotion to major for his "gallant and distinguished conduct" in the defense of Fort Brown, Texas. He fought in the Battle of Monterrey and the Siege of Veracruz, which he then governed as military commandant for four months. He was appointed a brevet lieutenant colonel for "gallant and meritorious conduct in the several conflicts at Monterrey, Mexico."