Montgomery, Ala. was the initial capital of the Confederacy until the government relocated to Richmond, Va., in May 1861. Richmond fell to federal occupation in 1865. The capital briefly shifted to Danville, Va. before the war ended.
The Confederate government relocated to Richmond because it was a large, well-established city with better accommodations, amenities and rail connectivity than Montgomery. Additionally, Richmond was also the capital city of Virginia, and by placing the Confederate seat of government there, officials hoped to cement the bond between the states that first seceded and the upper states of Virginia, Tennessee, Arkansas and North Carolina.