The growth of the Old Swiss Confederacy began as an alliance between the communities of the valleys in the Central Alps to facilitate the management of common interests such as free trade and to ensure the peace along the important trade routes through the mountains. In the late Middle Ages, this region belonged to the Holy Roman Empire, and because of its strategic importance, the Hohenstaufen emperors had granted it reichsfrei status in the early 13th century. As reichsfrei regions, the cantons (or regions) of Uri, Schwyz, and Unterwalden were under the direct authority of the emperor without any intermediate liege lords and thus were largely autonomous.
With the rise of the Habsburg dynasty, the kings and dukes of Habsburg sought to extend their influence over this region and to bring it under their rule; as a consequence, a conflict ensued between the Habsburgs and these mountain communities who tried to defend their privileged status as reichsfrei regions. The three founding cantons of the Schweizerische Eidgenossenschaft, as the confederacy was called, were joined in the early 14th century by the city states of Lucerne, Zürich, and Bern, and they managed to defeat Habsburg armies on several occasions. They also profited from the fact that the emperors of the Holy Roman Empire, for most of the 14th century, came from the House of Luxembourg and regarded them as potential useful allies against the rival Habsburgs. By 1460, the confederates controlled most of the territory south and west of the Rhine to the Alps and the Jura mountains. At the end of the 15th century, two wars resulted in an expansion to thirteen cantons (Dreizehn Orte): in the Burgundian Wars of the 1470s, the confederates asserted their hegemony on the western border, and their victory in the Swabian War in 1499 against the forces of the Habsburg emperor Maximilian I ensured a de facto independence from the empire. During their involvement in the Italian Wars, the Swiss brought the Ticino under their control.