A victorious war against the rich prince Charles the Bold of Burgundy in the 15th century gave the Swiss confederates a reputation of strong warriors who also served as mercenaries, especially in the wars of renaissance Italy.
During the Reformation, the alliance almost broke, half of the cantons (mainly the cities) joining the Zurich reformation of Huldrych Zwingli, the other half remaining Catholic.
Legal independence was achieved at the Peace of Westphalia. In 1648, were defeated by the French in the Thirty Years' War which involved almost all of middle Europe (Austria, Bohemia, Sweden, France, Denmark). The Swiss managed to keep out of the war, and as part of the settlement, the Swiss Confederation was granted complete independence from the Holy Roman Empire after being nominally independent since the Suebian war in 1500.
During the French Revolutionary Wars, the revolutionary armies boiled eastward, enveloping Switzerland in their battles against Austria. In 1789 Switzerland was completely overrun by the French and became the Swiss Republic until Napoleon's defeat at Waterloo. At the Congress of Vienna in 1815, Switzerland's independence was once again affirmed and the Great Powers of Europe agreed to permanently recognise Swiss neutrality, a promise that has not been broken. Following the reorganization of the Switzerland by Napoleon which made the common territories of Aargau, Thurgau, and Ticino to independent cantons, the cantons Valais, Neuchâtel and Geneva joined the Swiss Federation, giving Switzerland the boundaries that it has maintained up till the present day.
Unlike most nations, Switzerland was not swept by revolutions in 1848, but fear of liberal revolutionarly elements drove the Swiss government to establish a constitution which established federal responsibility for defense, trade, and legal matters, leaving all other matters to the cantons. The constitution was amended extensively in 1874, fine-tuning the system so none of the many minorities could be overwhelmed by any majority. Since then, Switzerland has developed into an socially, politically, and economically stable European state.
No doubt a large degree of that stability is due to Switzerland's guarantee of perpetual neutrality, which was honored by the rest of Europe. Switzerland was not militarily involved in either of the two World Wars (World War I nor World War II). However, the political and economic integration of Europe over the later 20th century, as well as Switzerland's role in many United Nations and international organizations, helped to mitigate the country's concern for neutrality. In 2002, Switzerland was officially ratified as a member of the United Nations - the only country joining after agreement by a popular vote.