John Gray Foster was born in Whitefield, New Hampshire on May 27, 1823, and grew up in nearby Nashua, New Hampshire. Graduating from the U.S. Military Academy at West Point in 1846, he served as an engineer in the Mexican War and was wounded at the Battle of Molino del Rey. At the outbreak of the Civil War, Foster was a captain in command of the garrison at Fort Moultrie, Charleston Harbor, South Carolina. He moved his force to Fort Sumter and became second-in-command to Maj. Robert Anderson.
Foster was appointed brigadier general of volunteers on October 23, 1861. He commanded the first brigade of the Burnside Expedition in eastern North Carolina in the spring of 1862. When General Burnside was called to service in Virginia, Foster took over command of the Department of North Carolina and was promoted to major general of volunteers on July 18, 1862. As department commander, Foster led the Goldsboro Expedition, better known in eastern North Carolina as "Foster's Raid," in December 1862, winning an important, though short-lived victory at the Battle of Goldsboro Bridge.
Foster was sent to Tennessee in 1863 to assume command of the Department of the Ohio and Army of the Ohio, but his service was cut short due to injuries he sustained from a fall from his horse. Upon his recovery, he took command of the Department of the South and forced the surrender of Savannah, Georgia. He was then transferred to command the Department of Florida, where he remained until war's end. At the end of the war, Foster held dual rank as major general of volunteers and brevet major general in the regular army.
Remaining in the army after the war, Foster's rank was reduced to his previous status as captain. He was promoted to lieutenant colonel of engineers in 1867 and colonel of engineers in 1871. He became an expert on underwater demolition and wrote a manual on the subject in 1869. From 1871 to 1874 he served as assistant to the army's Chief of Engineers in Washington, D.C. Foster died on September 2, 1874.