Miles was born in Baltimore, Maryland on May 4, 1804. He was a cadet at the United States Military Academy at West Point from June 24, 1819, to July 1, 1824. He was commissioned a brevet second lieutenant in the 7th Infantry Regiment. Nine years later Miles was promoted to first lieutenant in 1833 and captain in 1836. He served as Assistant Quartermaster from January 16, 1839 to September 30, 1845. In 1846, he served in the Mexican–American War. At the Siege of Fort Texas he was cited for Gallantry and "Meritorious Conduct" in the defense of Fort Texas and was promoted to the rank of major.