Interestingly enough some of the earliest known remains of Homo of any kind in Europe have been found in Spain. Spain is also thought to have been the last refuge of the Neanderthals as well as one of the few places that were inhabitable and inhabited throughout the ice ages.
Early Spain and Roman Era
The earliest inhabitants of the Iberian peninsula we have any profound knowledge of were Iberians, Celts (related to the Gaulish, Britannic and Central European Celts in language and culture) and Basques. As most of these groups had little to no written records we only know of them due to the descriptions of the Greek, Punic and later Roman settlers and conquerors, who colonized Spain from the South starting in the 3rd century BC. Roman culture lasted on the peninsula for roughly half a millennium, when in the age of migrations the Visigoths conquered the Roman province of Hispania.
Interestingly enough most inhabitants of the area kept speaking Latin or rather Latin-derived languages/dialects and only a handful of Germanic words entered the Spanish language ("ganso" being the most commonplace). Soon after their conquest, the Visigoths formed a number of rival "kingdoms" and petty noble states in almost constant conflict in ever-shifting shaky alliances with or against one another, giving rise to constant wars.
Muslim conquest and "al-Andalus"
In 711 one Visigoth ruler apparently called for the Umayyad Muslims to "help" in his fight against some rival or other. (The historical records for this era in Spain are rather bad and there are for example no contemporary Muslim sources whatsoever.) This proved more successful than he could have imagined, and by the end of the 8th century most of the peninsula was in Muslim hands. While the almost eight hundred years of both Christian and Muslim rulers on the Iberian peninsula was by no means peaceful, the modern narrative of a somehow concerted effort to "regain" the "lost lands" for Christendom was never the first, second or any priority for the majority of the Christian rulers. As a matter of fact, many times Christian rulers entered into alliances with Muslim rulers against other Christian rulers and vice versa. While the situation for Muslims in Christian lands and vice versa and Jews in either depended very much on the mood of the ruler and could lie anywhere on a range from benevolent ignorance to murder and expulsion, religious minorities had it a lot better in Spain than in most of the rest of Europe at that time. In fact the Sephardi Jews (named after the Hebrew word for Spain) were at that time not only one of the most important groups inside Spain in terms of science and education, but also dominant among the Jewish people, worldwide. During that time an estimated 90% of Jews were Sephardi. (In the 19th century, on the other hand, roughly 90% of Jews were Ashkenazim [German and Eastern European, and primarily Yiddish-speaking].) However, this period ended when through conquest and marriage the kingdoms of Castille and Aragon as well as a couple of minor Christian lands were united and their rulers started a war of conquest against the Muslim rulers. In the process of re-conquering Spain, many of the great mosques and synagogues were desecrated and converted into Christian churches.
Some of the most glorious historical attractions in Spain date from the period of Muslim rule, including the The Mezquita, built as the Great Mosque of Córdoba and the Medina Azahara, also in Córdoba and now in ruins but still visitable as such and built as the Madinat al-Zahra, the Palace of al-Andalus; and the Alhambra in Granada, a splendid, intact palace. There are also two synagogues still standing that were built during the era of Muslim Spain: Santa María la Blanca in Toledo and the Synagogue of Córdoba, in the Old City.
Reconquista and Imperial era
This so called "reconquista" was completed in 1492 with the fall of Granada, and all Jews were forced to leave Spain or convert that year; by 1526, all Spanish Muslims had suffered the same fate. 1492 also marks the point when Spain started to become the world's strongest Empire with territories in North, Central and South America, Africa, and the Philippines (named after Spanish king Felipe). The "new Christians" as they were called were often not sincere in their (forced) conversions (go figure) and to ensure religious "purity", the notorious Spanish inquisition was set up. Genetic studies made in modern times suggest that a large percentage of modern Spaniards have at least partial Jewish and/or Muslim ancestry, which might surprise some, as the concept of being a "true Christian" (rather than a "converso") soon began to get hereditary overtones, with the expulsion of all the descendants of forced converts from Islam in 1609.
Under the House of Habsburg, Spain became a personal union with the Austrian Empire, and reached its height of power in Europe during the 16th and early 17th centuries, controlling much of Benelux and Italy. Spain was weakened as the House of Habsburg lost the Thirty Years' War in 1648.
The colonization of Central and South America as well as Mexico was particularly profound, with the deaths of millions of native people through disease, war and outright murder as the Spanish sought riches in these 'undiscovered' lands. Today many of the countries in this area are defined by Hispanic language and culture (Spanish is today the world's second most spoken native language after Mandarin and before English, and Catholicism dominates throughout the former Spanish colonies). The 19th century saw independence movements fight back against the kingdom of Spain, with leaders such as Simón Bolívar and Augustín de Iturbide successfully creating new independent nations throughout Latin America. By 1898 Spain lost the majority of its remaining territories during the Spanish-American War: it lost Cuba and then sold Puerto Rico, the Philippines, and Guam to the United States. The war of 1898 was a huge shock to Spanish culture and shattered Spain's self-image of a first-rate power, and it thus inspired a whole literary movement known as the generation of '98.
The 20th century
Spain experienced a devastating civil war between 1936 and 1939 that killed half a million Spaniards and ushered in more than 30 years of dictatorship under Generalissimo Franco. The civil war originated from a mostly failed coup in Spanish North Africa (today part of Morocco) against Spain's left-wing popular front regime (a popular front was in those days a regime including communist/socialist parties as well as liberal, Christian Democrat or even conservative parties and originated in France as a response to fascism). Initially, The fascist side was not led by Franco, but a number of other generals; however, the other leaders soon died in plane crashes or were otherwise pushed to the side. Although the League of Nations (a precursor of today's United Nations) attempted to make intervention impossible, Mussolini's Italy and Nazi Germany gleefully ignored this by aiding the nationalist (Franco) side, while the Soviet Union and to some extent Mexico provided aid to the Republican (popular front) side. Another thing the Republican side tried to do to help win the war was to call for volunteers in the so-called "international brigades", and around 20,000 Brits, Americans, Frenchmen and even Germans did in fact join the fight on their side. However, the Republican side was plagued by lack of weapons and ammunition (some of their rifles were produced in the 19th century) as well as infighting between communists and anarchists and Stalinist purges ordered by the super-paranoid "supporters" of Republican Spain in Moscow. As many people of that generation fought in the Spanish Civil War (including George Orwell, Ernest Hemingway and later German chancellor Willy Brandt) there is a lot of well-written literature (and some films) that while not always historically accurate manage to perfectly capture the spirit of vain idealism that made many of the interbrigadistas go to Spain in the first place.
After the war was won for Franco through superior fire-power as well as military aid by the Nazis (such as the war-crime of bombing Guernica), Franco managed to unify the not at all homogeneous nationalist forces behind his less-than-charismatic leadership and hold onto power through the Second World War (in which he stayed neutral) until his death, upon which he was to be succeeded by King Juan Carlos. The Spanish Civil War is still in some sense an open wound as it was hardly ever talked about during the days of Franco's regime and to this day Conservatives and Catholics (the Republicans were pretty anti-clerical) are sometimes apologetic toward Franco and the "necessity" of the war. Franco's legacy was that the historically important regional identities and languages (such as Catalan and Basque) were brutally suppressed and a policy of strong national identity under the Spanish/Castillian language was promoted. While violent groups such as ETA (see below) were active even during Franco's time, there was hardly any organized opposition, either violent or peaceful, for most of Franco's reign. Additionally, Franco oversaw Spain's rapid economic expansion with its industrialization in the 1960's. Spain also entered NATO (though not the EU or any of its predecessors) while still governed by Franco. Spain's messy divorce (to say the least) from its African colonies that happened in the latter days of Franco's life is also one of the reasons for the conflict in Western Sahara, a former Spanish colony.
With the peaceful transition to democracy in 1978 the restrictions on regional identity were lifted, with autonomy granted to several regions. The nature of the transition meant that there was little justice for those who had suffered under the Franco dictatorship and divisions still remain. Shortly after King Juan Carlos - to the surprise of many - insisted on the country becoming a parliamentary democracy with a figurehead king as nominal head of state, a number of right-wing generals in what is now known as 23F tried to overthrow the democratic transition on 23 February 1981. The coup failed mostly due to lack of popular support and because the king - in his capacity of commander-in-chief - appeared on television in full uniform to order the soldiers back into their barracks, thus throwing his lot in with democracy.
The Basque country in Spain's north that had begun violent resistance in 1959 against Franco continued its campaign of bombings and assassinations into the democratic era with the terrorist ETA (Euskadi ta Askatasuna; Basque for Basque country and freedom) group, despite the region having been provided with a high degree of autonomy. The group declared a ceasefire in 2011 and the armed struggle appears over for the time being. Even in the "democratic" 1980s, (under longtime Prime minister Felipe González [PSOE 1982-1996]) the Spanish government responded with methods that are now known to have included "death squadrons" to combat terrorism.
Uncertain times in the third millennium
The 2000's saw more economic expansion as well as a housing price boom that subsequently collapsed, leaving Spain with high unemployment and economic difficulties. As a member of U.S. President G.W. Bush's "coalition of the willing" in the "war on terror", Spain was hit by a terrorist attack on a couple of suburban trains in Madrid on 11 March 2004 (now known in Spain as 11M) just a few days before a general election. Prime minister Aznar's (Popular Party, conservative) insistence that the perpetrators were Basque terrorists whom the social democratic opposition PSOE (Partido Socialista Obrero Español) wanted to negotiate with led to an upset win for Jose Luis Rodriguez Zapatero of the center-left PSOE. His government, however, broke down in late 2011 as an early result of the economic crisis that hit Spain particularly hard. Currently Spain is led by a rather unpopular caretaker conservative government under Mariano Rajoy, who lost the elections of late 2015, resulting in a hung parliament and another round of elections resulting in yet another hung parliament. The economically important Catalan region is also increasing in its demands for independence from Spain.
Spain holds a historical attachment to its neighbors within the Iberian Peninsula, Andorra and Portugal, to its former colonies, to former citizens and their descendants, and to a special category of former citizens, namely Sephardic Jews.
The population of Spain is growing in large part due to migration by people from relatively poor or politically unstable areas of Latin America, such as Colombia, Cuba, Ecuador, El Salvador or Peru; other parts of Europe, especially Eastern Europe; and Africa and Asia, particularly areas that have a historical or linguistic attachment to Spain. There is also an important segment of immigration that consists mainly of retired people, and people running businesses for them and foreign tourists, coming from wealthier European Union countries such as the United Kingdom, France, Germany, Benelux and the Nordic countries, established all along the Mediterranean shore, especially in the Costa Blanca (Alicante), Costa del Sol (Málaga) and the Balearic Islands.
Internally there have always been migrations from poorer rural areas (such as Andalusia) to the cities and to jobs in construction and tourism. Due to the economic crisis of the 2000s and 2010s, youth unemployment has risen to unbearable levels in the 50% range and quite a number of young people have semi-permanently fled the country to other European Union countries such as Germany to study, work or do internships either until things get better in Spain or forever.