William Montgomery Gardner was born on June 8, 1824 at Augusta, Georgia. He graduated from the United States Military Academy in 1846. He served in the Mexican–American War in the 2nd U.S. Infantry Regiment. He was wounded at the Battle of Churubusco, Mexico and the Battle of Contreras, Mexico. Gardner was promoted to captain on March 3, 1855. He resigned from the U.S. Army on January 19, 1861.