After graduating from West Point in 1825, Anderson was appointed a second lieutenant. He served in the Black Hawk War of 1832, the Seminole War and the Mexican War. In November 1860, he was appointed as a major to service at Fort Sumter, in Charleston Harbor, South Carolina, with his headquarters at Fort Moultrie. After the secession of South Carolina from the Union, his command came under attack. He surrendered from Fort Sumter on April 14, 1861, two days after the attacks began. He was promoted to Brigadier General and put in command of the Department of Kentucky, later the Department of the Cumberland, until disability forced his retirement in October 1863.