Barton was born in Fredericksburg, Virginia, on September 8, 1829, to Thomas Bowerbank Barton and Susan Catherine Stone Barton. At the age of 15, he was accepted into the United States Military Academy, graduating in 1849. Following his graduation, Barton served in various frontier posts in New Mexico Territory and Texas, where he participated in campaigns against the Comanche Indians. By 1861, Barton had become a Captain in the United States Army.
With the outbreak of the Civil War, he resigned his commission and joined the 3rd Arkansas Infantry as a lieutenant colonel in the Confederate army. Serving under Gen. Robert E. Lee, Barton saw action at the battles of Cheat Mountain and Greenbrier River, and later with Gen. Thomas "Stonewall" Jackson as chief engineer during the Valley Campaign in 1862. Promoted to brigadier general in March 1862, Barton was assigned to Gen. E. Kirby Smith in the Department of East Tennessee, where for a short time during the June 1862 Cumberland Gap Campaign, Barton led the 4th Brigade, consisting of Anderson's Virginia battery as well as Alabama and Georgia regiments. Later transferred with Maj. Gen. Carter L. Stevenson's division to Vicksburg, Mississippi, Barton was captured following the Siege of Vicksburg on July 4, 1863. Released following a prisoner exchange, Barton was assigned command of the Virginia brigade once led by Lewis Armistead, serving under Maj. Gen. George Pickett. Stationed at Kinston, North Carolina, for the remainder of the year, Barton was commanding one of the forward columns marching on New Bern, in February 1864, when he was censured after Pickett had issued a formal complaint against him for lack of cooperation. He was transferred to Gen. Robert Ransom's command at Drewry's Bluff. However, Barton was again relieved of command following the Battle of Drewry's Bluff when Ransom issued a similar charge, despite accounts of Barton's gallantry during the battle as well as his unit being the first to reach the Union guns. Barton's brigade was assigned to Col. Birkett D. Fry. Barton was later returned to command due to the intervention of other officers on his behalf and assigned to a brigade defending Richmond, Virginia, under Lt. Gen. Richard S. Ewell. He remained at Chaffin's Farm until the eventual evacuation of Richmond and joined the retreating forces under Maj. Gen. Custis Lee. Barton was captured on April 6, 1865 at the Battle of Sayler's Creek along with eight other Confederate Generals. Imprisoned for three months at Fort Warren in Boston, Massachusetts, he was released after signing a loyalty oath to the Union
After the war, Barton returned to Fredericksburg, where he began practicing chemistry, eventually becoming one of the most prominent chemists in the United States. In 1900, while visiting his son in Washington, D.C., he died suddenly. He was buried in the City Cemetery in Fredericksburg, Virginia.