The Electorate of Bavaria (German: Kurfürstentum Bayern) was an independent hereditary electorate of the Holy Roman Empire from 1623 to 1806, when it was succeeded by the Kingdom of Bavaria.
The Wittelsbach dynasty which ruled the Duchy of Bavaria was the younger branch of the family which also ruled the Electorate of the Palatinate. The head of the elder branch was one of the seven prince-electors of the Holy Roman Empire according to the Golden Bull of 1356, but Bavaria was excluded from the electoral dignity. In 1621, the Elector Palatine Frederick V was put under the imperial ban for his role in the Bohemian Revolt against Emperor Ferdinand II, and the electoral dignity and territory of the Upper Palatinate was conferred upon his loyal cousin, Duke Maximilian I of Bavaria. Although the Peace of Westphalia would create a new electoral title for Frederick V's son, with the exception of a brief period during the War of the Spanish Succession, Maximilian's descendants would continue to hold the original electoral dignity until the extinction of his line in 1777. At that point the two lines were joined in personal union until the end of the Holy Roman Empire. In 1805, after the Peace of Pressburg, the then-elector, Maximilian Joseph, raised himself to the dignity of King of Bavaria, and the Holy Roman Empire was abolished the next year.