In and around the environment of Almeida, evidence of human occupation can be found dating back to the Bronze Age and Iron Age. Evidence has also been found of Roman occupation followed by the Suevi and the Visigoths.
The first fortifications constructed in the settlement were constructed by the Muslims who occupied the village until Christian reconquest of the Iberian Peninsula. It was during this time that the current name was first used, in the form of the Arabic المائدة al-Ma'ida ('the table'). This name refers to a legend that an ornate bejeweled table captured by Tariq ibn Ziyad was the dining table of King Solomon.
The village of Almeida was captured from the Moors by the second king of Portugal, Sancho I in the 12th century because of its strategic position on the new country of Portugal's border with Spain. So important to the security of the country, Sancho had the village heavily fortified. The castle was refortified on three further occasions by King Dinis, King Manuel I and by King João VI. The present 12 pointed star fortification was constructed in 1641 to a Vaubanesque plan on which the French military engineer is believed to have personally worked, during the castle's final stages of completion.
During the Seven Years' War (1754 to 1763) which involved most of the great powers of Europe, Spain with the help of France launched an attack on Portugal due to its alliance with Great Britain. As a result of the invasion Almeida was captured by Spain in 1762.
The fortress around the town guards an important cross-border road from Spain, and underwent several sieges. The siege of 1810, during the Peninsular War, ended spectacularly when a chance shell ignited the main gunpowder magazine, which exploded, killing 500 defenders and destroying most of the town.