The Thirty Years War was ended by the Peace of Westphalia which was referred to as the “Peace of Exhaustion” by contemporaries. The Peace of Westphalia was not one specific treaty but rather a collection of treaties commonly linked by the fact that they brought the Thirty Years War to an end.
France and Sweden had already agreed at the Treaty of Hamburg that there should be a European return to the status quo of 1618.
The German Electors favoured 1618 as their baseline.
In September 1640, the Electors were summoned by Ferdinand III to Regensburg where the emperor attempted to get the Electors to agree to preserving the Peace of Prague. He failed. Frederick William of Brandenburg specifically rejected Prague as the basis of any settlement.
In July 1641, Brandenburg and Sweden signed a truce. Many German princes followed this example of Brandenburg’s to show their displeasure with Ferdinand III. However, Ferdinand III had already started separate negotiations with the French and Dutch at Munster and with the Swedes at Osnabruck.
Peace negotiations continued at the same time as the military campaigns. In 1642, a Swedish army defeated an Imperial army at Breitenfeld at the same time as Swedish and Imperial diplomats were examining potential peace terms. Such occurrences happened as a show of strength to the opposition.
In 1645, Sweden and Saxony signed a peace agreement.
In 1647, Maximilian of Bavaria was forced by the Swedes and French to withdraw his support to Ferdinand. Maximilian reneged on this agreement in 1648, and Swedish and French forces devastated Bavaria leaving Maximilian in a position where he could not do anything else except sign a truce with Sweden and France.
The French persuaded Ferdinand III to exclude Spain from the peace negotiations but the United Provinces and Spain did sign a peace settlement at Munster in 1648 thus bringing to an end 80 years of hostility between the Spanish government and the Dutch commonly known as the Revolt of the Netherlands.
France gained the bishoprics of Metz, Toul and Verdun; Breisach and Philippsburg; Alsace and part of Strasburg.
Sweden gained West Pomerania, Wismar, Stettin, Mecklenburg; the bishoprics of Verden and Bremen which gave her control over the estuaries of the Elbe and Weser.
Brandenburg gained East Pomerania; the archbishopric of Magdeburg and Halberstadt.
Bavaria kept the Upper Palatinate and the Electoral title that went with it. The Lower Palatinate was restored to Charles Louis, the son of Frederick and an 8th Elector’s title was made for him.
Saxony kept Lusatia.
Bohemia remained an hereditary domain.
Spain recognised the United Provinces as a sovereign state.