Madison was created in 1836 when former federal judge James Duane Doty purchased over a thousand acres (4 km˛) of swamp and forest land on the isthmus between Lakes Mendota and Monona within the Four Lakes region, with the intention of building a city on the site.
The Wisconsin Territory had been created earlier that year and the territorial legislature had convened in Belmont, Wisconsin. One of the legislature's tasks was to choose a permanent location for the territory's capital. Doty lobbied aggressively for the legislature to select Madison as the new capital, offering buffalo robes to the freezing legislators and promising choice Madison lots at discount prices to undecided voters . He had James Slaughter plat two cities in the area, Madison and "The City of Four Lakes," near present-day Middleton.
Doty named the city Madison for James Madison, the 4th President of the U.S. who had died on June 28, 1836 and he named the streets for the other signers of the U.S. Constitution.
Despite the fact that Madison was still only a city on paper, the territorial legislature voted on November 28 in favor of Madison as its capital, largely because of its location halfway between the new and growing cities around Milwaukee in the east and the long established strategic post of Prairie du Chien in the west, and because of its location between the highly populated lead mining regions in the southwest and Wisconsin's oldest city, Green Bay in the northeast.
Being named for the much-admired founding father James Madison, who had just died, and having streets named for each of the 39 signers of the Constitution, may have also helped attract votes. The cornerstone for the Wisconsin capitol was laid in 1837, and the legislature first met there in 1838. Madison was incorporated as a village in 1846, with a population of 626. When Wisconsin became a state in 1848, Madison remained the capital, and the following year it became host to the University of Wisconsin–Madison.
The Milwaukee & Mississippi Railroad (a predecessor of what would become known as the Milwaukee Road) connected to Madison in 1854. Madison became a city in 1856, with a population of 6,863, leaving the unincorporated remainder as a separate Town of Madison.  The original capitol was replaced in 1863. The second capitol burned in 1904, and the current capitol was built between 1906 and 1917.
During the American Civil War, Madison served as a center of the Union Army in Wisconsin. The intersection of Milwaukee, East Washington, Winnebago, and North Streets is known as Union Corners, as a tavern located there was the last stop for Union soldiers before heading to fight the Confederates. Camp Randall, on the west side of Madison, was built and used as a training camp, a military hospital, and a prison camp for captured Confederate soldiers. After the war ended, the Camp Randall site was absorbed into the University of Wisconsin- Camp Randall Stadium was built over the site in 1917. In 2004 the last vestige of active military training on the site was removed when the stadium renovation replaced a firing range used for ROTC training.