Let’s start from the beginning.
In 476 AD the barbarian Odoacer deposed Romulus Augustus, thus putting a definitive end to the Roman Empire in the West.
With the deposition of the Emperor, Italy soon became a territory of conquest, which alternated domination that characterized the different decades and geographical areas by the Byzantines, the Franks and the Lombards.
In 771 Pope Stephen III called for the intervention in Italy of the Frankish king Charlemagne to rid the north of the peninsula from the domain of Desiderius, king of the Lombards.
Charles, having unified the part of Italy which had conquered (basically the northern and central parts of the country) took the title of Rex Francorum Longobardorum and ensuring full autonomy to the papacy.
The result of this conquest, which is defined over the centuries as Regnum Italiae, passed from hand to hand over the following centuries in which different sovereigns took turns on the throne, but always under papal approvement.
At the end of the tenth century, the German Emperor Otto of Saxony descended in Italy and after having defeated Berengar, at that time the king, the crown attached to the Roman Germanic Empire, gradually reducing the power of the pope and being crowned emperor of what was later called Holy Roman Empire, the first form of the German Reich, which included most of Germany and northern Italy as well as numerous territories east of the two countries.