The Duchy of Bavaria (German: Herzogtum Bayern) was, from the sixth through the eighth century, a frontier region in the southeastern part of the Merovingian kingdom. It was settled by Bavarian tribes and ruled by dukes (duces) under Frankish overlordship. A new duchy was created from this area during the decline of the Carolingian Empire in the late ninth century. It became one of the stem duchies of the East Frankish realm which evolved as the Kingdom of Germany and the Holy Roman Empire.
During internal struggles of the ruling Ottonian dynasty, the Bavarian territory was considerably diminished by the separation of the newly established Duchy of Carinthia in 976. Between 1070 and 1180 the Holy Roman Emperors were again strongly opposed by Bavaria, especially by the ducal House of Welf. In the final conflict between the Welf and Hohenstaufen dynasties, Duke Henry the Lion was banned and deprived of his Bavarian and Saxon fiefs by Emperor Frederick Barbarossa. Frederick passed Bavaria over to the House of Wittelsbach, which held it until 1918. The Bavarian dukes were raised to prince-electors during the Thirty Years' War in 1623.