Andrew Jackson appointed Hays to the United States Military Academy, where he graduated in 1840 alongside William T. Sherman, George H. Thomas, and Richard S. Ewell.
He was wounded at the Battle of Molino del Rey, and was subsequently appointed a brevet captain for Contreras and Churubusco and major for Chapultepec.
As a lieutenant colonel, Hays commanded a brigade of horse artillery under Henry Hunt in 1861–62 in the Army of the Potomac, serving with distinction at the Battle of Seven Pines during the Peninsula Campaign.
Hays was appointed brigadier general of volunteers in November 1862 and assigned command of an infantry brigade in Maj. Gen. William H. French's division in the II Corps.
At the expiration of his term in February 1865, Hays rejoined the Army of the Potomac at Petersburg and served again in the II Corps, this time commanding the 2nd Division.
He was appointed a brevet brigadier general in the regular army on March 13, 1865, for gallant conduct, but on April 6 he was relieved of command for sleeping on duty and thus failing to prepare his troops for departure as they pursued Confederate forces.