During the invasion of Naples by the Lombards the population was about 30,000-35,000 inhabitants.
In 615, under Giovanni Consino, Naples rebelled for the first time against the power of Ravenna, the emperor in Italy. In response, a first duchy was created in 638 by Emperor Eleutherius.
At that time the Duchy of Naples was a region corresponding today to the province of Naples, the area surrounding Vesuvius, the Fleemesian Fields, the Sorrentine Peninsula, Giugliano, Aversa, Afragola, Nola and the islands of Ischia and Procida. Capri was part of the Duchy of Amalfi.
In 661 Naples obtains from Emperor Constantine II the appointment of a local duke, Basilius, whose submission to the emperor soon became more formal than real.
In 763 Duke Stephen II changed his allegiance to that of the Pope.
In 840 Duke Sergius I made the succession of the hereditary duchy, and from that time Naples became independent.
At that time, the city was essentially a military center, ruled by an aristocracy of warriors and landowners, although it was obliged to return much of its internal territory to the neighboring Lombards.
Naples was not a merchant city as were other maritime towns of Campania like Amalfi and Gaeta, but its fleet was respectable, it participated in the important battle of Ostia against the Saracens in 849.
Naples did not hesitate to ally with “infidels” for its own benefit. Thus in 836 it asked the support of the Saracens to repel the Lombard troops who besieged the city and send them back to the nearby Duchy of Benevento (Benevento).
The Neapolitan Duchy enjoyed its best hours under Duke-Bishop Athanasius and his successors, including Gregorio IV and John who participated in the Battle of Garigliano in 915.
Naples lost importance in the tenth century until it was captured by a hereditary rival, Pandulf IV of Capua.
In 1027, Duke Sergius IV gave the county of Aversa to a band of Norman mercenaries led by Rainulf Drengot which he needed in his war against the principality of Capua.
Chief of the last of the southern Italian states, Sergius VII was forced to surrender in 1137 to the Norman Roger II of Sicily of the Hauteville family who had proclaimed himself King of Sicily seven years earlier.
Under the new kingdom, the city was administered by a compalazzo (count-palatine), with little independence left to the Neapolitan patriarchs.
At that time Naples had 30,000 souls, but most trade activities were outsourced to foreigners, mainly from Pisa and Genoa.
Apart from the church of San Giovanni, the Norman buildings in Naples were mostly extensions, including castles (Castle of the Egg, Capua), walls and doors.