Numidia was the ancient kingdom of the Numidians located in northwest Algeria, but later expanding across what is today known as Tunisia, Libya, and some parts of Morocco. Numidia is considered to be the first state of Algeria. The polity was originally divided between the Massylii in the east and the Masaesyli in the west. During the Second Punic War (218–201 BC), Masinissa, king of the Massylii, defeated Syphax of the Masaesyli to unify Numidia into one kingdom. The kingdom began as a sovereign state and later alternated between being a Roman province and a Roman client state.
Numidia, at its largest extent, was bordered by Mauretania to the west, at the Moulouya River, Africa Proconsularis to the east, the Mediterranean Sea to the north, and the Sahara to the south. It was one of the first major states in the history of Algeria and the Berbers.
The Greek historians referred to these peoples as "Νομάδες" (i.e. Nomads), which by Latin interpretation became "Numidae" (but cf. also the correct use of Nomades). Historian Gabriel Camps, however, disputes this claim, favoring instead an African origin for the term.
The name appears first in Polybius (second century BC) to indicate the peoples and territory west of Carthage including the entire north of Algeria as far as the river Mulucha (Muluya), about west of Oran.
The Numidians were composed of two great tribal groups: the Massylii in eastern Numidia, and the Masaesyli in the west. During the first part of the Second Punic War, the eastern Massylii, under their king Gala, were allied with Carthage, while the western Masaesyli, under king Syphax, were allied with Rome. The Kingdom of Masaesyli under Syphax extended from the Moulouya river to Oued Rhumel.
However, in 206 BC, the new king of the eastern Massylii, Masinissa, allied himself with Rome, and Syphax of the Masaesyli switched his allegiance to the Carthaginian side. At the end of the war, Numidia was under the rule of Masinissa of the Massylii.