The 19th century was a turbulent time for Spain. Those in favour of reforming Spain's government vied for political power with conservatives, who tried to prevent reforms. Some liberals, in a tradition that started with the Spanish Constitution of 1812, sought to limit the power of the monarchy of Spain and to establish a liberal state. The reforms of 1812 were overturned when King Ferdinand VII dissolved the Constitution and ended the Trienio Liberal government.

Twelve successful coups were carried out between 1814 and 1874.

In 1868, popular uprisings led to the overthrow of Queen Isabella II of the House of Bourbon. Two distinct factors led to the uprisings: a series of urban riots and a liberal movement within the middle classes and the military (led by General Joan Prim) concerned with the ultra-conservatism of the monarchy.

In 1873, Isabella's replacement, King Amadeo I of the House of Savoy, abdicated due to increasing political pressure, and the short-lived First Spanish Republic was proclaimed.

After the restoration of the Bourbons in December 1874, Carlists and Anarchists emerged in opposition to the monarchy.

Alejandro Lerroux, Spanish politician and leader of the Radical Republican Party, helped bring republicanism to the fore in Catalonia, where poverty was particularly acute. Growing resentment of conscription and of the military culminated in the Tragic Week in Barcelona in 1909.

Spain was neutral in World War I. Following the war, wide swathes of Spanish society, including the armed forces, united in hopes of removing the corrupt central government, but were unsuccessful. Popular perception of communism as a major threat significantly increased during this period.

In 1923, a military coup brought Miguel Primo de Rivera to power; as a result, Spain transitioned to government by military dictatorship.

The consolidation of various militias into the Republican Army had started in December 1936. The main Nationalist advance to cross the Jarama and cut the supply to Madrid by the Valencia road, termed the Battle of Jarama, led to heavy casualties (6,000–20,000) on both sides. The operation's main objective was not met, though Nationalists gained a modest amount of territory.

Support for the Rivera regime gradually faded, and Miguel Primo de Rivera resigned in January 1930. He was replaced by General Dámaso Berenguer, who was in turn himself replaced by Admiral Juan Bautista Aznar-Cabañas; both men continued a policy of rule by decree. There was little support for the monarchy in the major cities. Consequently, King Alfonso XIII gave in to popular pressure for the establishment of a republic in 1931 and called municipal elections for 12 April of that year. The socialist and liberal republicans won almost all the provincial capitals, and following the resignation of Aznar's government, King Alfonso XIII fled the country.

At this time, the Second Spanish Republic was formed. It remained in power until the culmination of the Spanish Civil War.

The revolutionary committee headed by Niceto Alcalá-Zamora became the provisional government, with Alcalá-Zamora as president and head of state. The republic had broad support from all segments of society.

In May, an incident where a taxi driver was attacked outside a monarchist club sparked anti-clerical violence throughout Madrid and south-west Spain. The government's slow response disillusioned the right and reinforced their view that the Republic was determined to persecute the church.

In June and July, the Confederación Nacional del Trabajo, known as the CNT, called several strikes, which led to a violent incident between CNT members and the Civil Guard and a brutal crackdown by the Civil Guard and the army against the CNT in Seville. This led many workers to believe the Spanish Second Republic was just as oppressive as the monarchy, and the CNT announced its intention of overthrowing it via revolution. Elections in June 1931 returned a large majority of Republicans and Socialists.

Republican Manuel Azaña became prime minister of a minority government in October 1931.

With the onset of the Great Depression, the government tried to assist rural Spain by instituting an eight-hour day and redistributing land tenure to farm workers.

Fascism remained a reactive threat, helped by controversial reforms to the military. In December, a new reformist, liberal, and democratic constitution was declared. It included strong provisions enforcing a broad secularisation of the Catholic country, which included the abolishing of Catholic schools and charities, which many moderate committed Catholics opposed.

In 1933, the parties of the right won the general elections, largely due to the anarchists' abstention from the vote, increased right-wing resentment of the incumbent government caused by a controversial decree implementing land reform, the Casas Viejas incident, and the formation of a right-wing alliance, Spanish Confederation of Autonomous Right-wing Groups (CEDA). Another factor was the recent enfranchisement of women, most of whom voted for centre-right parties.

Events in the period after November 1933, called the "black two years", seemed to make a civil war more likely. Alejandro Lerroux of the Radical Republican Party (RRP) formed a government, reversing changes made by the previous administration and granting amnesty to the collaborators of the unsuccessful uprising by General José Sanjurjo in August 1932.

On 5 October 1934, in response to an invitation to CEDA to form part of the government, the Acción Republicana and the Socialists (PSOE) and Communists attempted a general left-wing rebellion. The rebellion had a temporary success in Asturias and Barcelona, but was over in two weeks. Azaña was in Barcelona that day, and the Lerroux-CEDA government tried to implicate him. He was arrested and charged with complicity. The October 1934 rebellion is regarded by historians as the beginning of the decline of the Spanish Republic and of constitutional government and constitutional consensus, as the Socialists and left Republicans had been integral to the new system and had governed for two years, yet the Socialists were now attempting a revolt against the democratic system and the left Republicans provided a sort of passive support for them.

In the last months of 1934, two government collapses brought members of the CEDA into the government. Farm workers' wages were cut in half, and the military was purged of Republican members.

Reversals of land reform resulted in the central and southern countryside in 1935 witnessing expulsions, firings and arbitrary changes to working conditions, with landowners' behaviour at times reaching "genuine cruelty", violence against farm-workers and socialists, which caused several deaths. One historian argued that the behaviour of the right in the southern countryside was one of the main causes of hatred during the Civil War and possibly even the Civil War itself.

Landowners taunted workers by saying that if they went hungry, they should "Go eat Republic!" Bosses fired leftist workers and imprisoned trade union and socialist militants, and wages were reduced to "salaries of hunger." A popular front alliance was organised, which narrowly won the 1936 elections.

Shortly after the Popular Front's election victory, various groups of officers, both active and retired, got together to begin discussing the prospect of a coup. It would be only be by the end of April that General Emilio Mola would emerge as the leader of a national conspiracy network. The Republican government acted to remove suspect generals from influential posts. Franco was sacked as chief of staff and transferred to command of the Canary Islands. Manuel Goded Llopis was removed as inspector general and was made general of the Balearic Islands. Emilio Mola was moved from head of the Army of Africa to military commander of Pamplona in Navarre. This, however, allowed Mola to direct the mainland uprising. General José Sanjurjo became the figurehead of the operation and helped reach an agreement with the Carlists. Mola was chief planner and second in command. José Antonio Primo de Rivera was put in prison in mid-March in order to restrict the Falange. However, government actions were not as thorough as they might have been, and warnings by the Director of Security and other figures were not acted upon.

By April 1936, nearly 100,000 peasants had appropriated 400,000 hectares of land and perhaps as many as 1 million hectares by the start of the civil war; for comparison, the 1931-33 land reform had granted only 6000 peasants 45,000 hectares. As many strikes occurred between April and July as had occurred in the entirety of 1931. Workers increasingly demanded less work and more pay. "Social crimes" - refusing to pay for goods and rent - became increasingly common by workers, particularly in Madrid. In some cases this was done in the company of armed militants. Conservatives, the middle classes, businessmen and landowners became convinced that revolution had already begun.

On 12 June, Prime Minister Casares Quiroga met General Juan Yagüe, who falsely convinced Casares of his loyalty to the republic. Mola began serious planning in the spring. Franco was a key player because of his prestige as a former director of the military academy and as the man who suppressed the Asturian miners' strike of 1934. He was respected in the Army of Africa, the Army's toughest troops. He wrote a cryptic letter to Casares on 23 June, suggesting that the military was disloyal, but could be restrained if he were put in charge. Casares did nothing, failing to arrest or buy off Franco.

German involvement began days after fighting broke out in July 1936. Adolf Hitler quickly sent in powerful air and armored units to assist the Nationalists. The war provided combat experience with the latest technology for the German military. However, the intervention also posed the risk of escalating into a world war for which Hitler was not ready. Therefore he limited his aid, and instead encouraged Benito Mussolini to send in large Italian units.

With the help of the British Secret Intelligence Service agents Cecil Bebb and Major Hugh Pollard, the rebels chartered a Dragon Rapide aircraft (paid for with help from Juan March, the wealthiest man in Spain at the time) to transport Franco from the Canary Islands to Spanish Morocco. The plane flew to the Canaries on 11 July, and Franco arrived in Morocco on 19 July.

On 12 July 1936, Falangists in Madrid killed police officer Lieutenant José Castillo of the Guardia de Asalto (Assault Guard). Castillo was a Socialist party member who, among other activities, was giving military training to the UGT youth. Castillo had led the Assault Guards that violently suppressed the riots after the funeral of Guardia Civil lieutenant Anastasio de los Reyes. (Los Reyes had been shot by anarchists during 14 April military parade commemorating the five years of the Republic.)

The uprising's timing was fixed at 17 July, at 17:01, agreed to by the leader of the Carlists, Manuel Fal Conde.

Control over Spanish Morocco was all but certain. The plan was discovered in Morocco on 17 July, which prompted the conspirators to enact it immediately. Little resistance was encountered. The rebels shot 189 people. Goded and Franco immediately took control of the islands to which they were assigned.

However, the timing was changed—the men in the Spanish protectorate in Morocco were to rise up at 05:00 on 18 July and those in Spain proper a day later so that control of Spanish Morocco could be achieved and forces sent back to the Iberian Peninsula to coincide with the risings there. The rising was intended to be a swift coup d'état, but the government retained control of most of the country.

On 18 July, Casares Quiroga refused an offer of help from the CNT and Unión General de Trabajadores (UGT), leading the groups to proclaim a general strike—in effect, mobilising. They opened weapons caches, some buried since the 1934 risings, and formed militias.

The rebels failed to take any major cities with the critical exception of Seville, which provided a landing point for Franco's African troops, and the primarily conservative and Catholic areas of Old Castile and León, which fell quickly. They took Cádiz with help from the first troops from Africa. The government retained control of Málaga, Jaén, and Almería. In Madrid, the rebels were hemmed into the Cuartel de la Montaña siege, which fell with considerable bloodshed. Republican leader Casares Quiroga was replaced by José Giral, who ordered the distribution of weapons among the civilian population. This facilitated the defeat of the army insurrection in the main industrial centres, including Madrid, Barcelona, and Valencia, but it allowed anarchists to take control of Barcelona along with large swathes of Aragón and Catalonia. General Goded surrendered in Barcelona and was later condemned to death. The Republican government ended up controlling almost all the east coast and central area around Madrid, as well as most of Asturias, Cantabria and part of the Basque Country in the north. The government retained control of Málaga, Jaén, and Almería. In Madrid, the rebels were hemmed into the Cuartel de la Montaña siege, which fell with considerable bloodshed. Republican leader Casares Quiroga was replaced by José Giral, who ordered the distribution of weapons among the civilian population.

A large air and sealift of Nationalist troops in Spanish Morocco was organised to the southwest of Spain. Coup leader Sanjurjo was killed in a plane crash on 20 July, leaving an effective command split between Mola in the North and Franco in the South. This period also saw the worst actions of the so-called "Red" and "White Terrors" in Spain.

On 21 July, the fifth day of the rebellion, the Nationalists captured the central Spanish naval base, located in Ferrol, Galicia.

In July 1936, British officials convinced Blum (the prime minister) not to send arms to the Republicans and, on 27 July, the French government declared that it would not send military aid, technology or forces to assist the Republican forces. However, Blum made clear that France reserved the right to provide aid should it wish to the Republic: "We could have delivered arms to the Spanish Government [Republicans], a legitimate government... We have not done so, in order not to give an excuse to those who would be tempted to send arms to the rebels [Nationalists]."

On 1 August 1936, a pro-Republican rally of 20,000 people confronted Blum, demanding that he send aircraft to the Republicans, at the same time as right-wing politicians attacked Blum for supporting the Republic and being responsible for provoking Italian intervention on the side of Franco.

However, the Blum government provided aircraft to the Republicans covertly with Potez 540 bomber aircraft (nicknamed the "Flying Coffin" by Spanish Republican pilots), Dewoitine aircraft, and Loire 46 fighter aircraft being sent from 7 August 1936 to December of that year to Republican forces.

The French also sent pilots and engineers to the Republicans. Also, until 8 September 1936, aircraft could freely pass from France into Spain if they were bought in other countries.

On 21 August 1936, France signed the Non-Intervention Agreement.

The Republic proved ineffective militarily, relying on disorganised revolutionary militias. The Republican government under Giral resigned on 4 September, unable to cope with the situation, and was replaced by a mostly Socialist organisation under Francisco Largo Caballero. The new leadership began to unify central command in the republican zone.

On 5 September, the Nationalists closed the French border to the Republicans in the battle of Irún.

On 15 September, San Sebastian, home to a divided Republican force of anarchists and Basque nationalists, was taken by Nationalist soldiers.

On the Nationalist side, Franco was chosen as chief military commander at a meeting of ranking generals at Salamanca on 21 September, now called by the title Generalísimo.

Franco won another victory on 27 September when his troops relieved the siege of the Alcázar in Toledo.

On 1 October 1936, General Franco was confirmed head of state and armies in Burgos. A similar dramatic success for the Nationalists occurred on 17 October, when troops coming from Galicia relieved the besieged town of Oviedo, in Northern Spain.

The Republican government was forced to shift from Madrid to Valencia, outside the combat zone, on 6 November.

In October, the Francoist troops launched a major offensive toward Madrid, reaching it in early November and launching a major assault on the city on 8 November.

Franco made another attempt to capture Madrid in January and February 1937, but was again unsuccessful.

The Battle of Málaga started in mid-January, and this Nationalist offensive in Spain's southeast would turn into a disaster for the Republicans, who were poorly organised and armed. The city was taken by Franco on 8 February.

A similar Nationalist offensive, the Battle of Guadalajara, was a more significant defeat for Franco and his armies. This was the only publicized Republican victory of the war. Franco used Italian troops and blitzkrieg tactics; while many strategists blamed Franco for the rightists' defeat, the Germans believed it was the former at fault for the Nationalists' 5,000 casualties and loss of valuable equipment.

The "War in the North" began in mid-March, with the Biscay Campaign. The Basques suffered most from the lack of a suitable air force.

German operations slowly expanded to include strike targets, most notably—and controversially—the bombing of Guernica which, on 26 April 1937, killed 200 to 300 civilians. Germany also used the war to test new weapons, such as the Luftwaffe Junkers Ju 87 Stukas and Junkers Ju-52 transport Trimotors (used also as Bombers), which showed themselves to be effective.

On 26 April, the Condor Legion bombed the town of Guernica, killing 200–300 and causing significant damage. The destruction had a significant effect on international opinion. The Basques retreated.

April and May saw the May Days, infighting among Republican groups in Catalonia. The dispute was between an ultimately victorious government—Communist forces and the anarchist CNT. The disturbance pleased Nationalist command, but little was done to exploit Republican divisions. After the fall of Guernica, the Republican government began to fight back with increasing effectiveness. In July, it made a move to recapture Segovia, forcing Franco to delay his advance on the Bilbao front, but for only two weeks. A similar Republican attack, the Huesca Offensive, failed similarly.

Mola, Franco's second-in-command, was killed on 3 June, in an airplane accident.

The Battle of Brunete, however, was a significant defeat for the Republic, which lost many of its most accomplished troops. The offensive led to an advance of 50 square kilometres (19 sq mi), and left 25,000 Republican casualties. The Battle of Brunete (6–25 July 1937), fought 24 kilometres (15 mi) west of Madrid, was a Republican attempt to alleviate the pressure exerted by the Nationalists on the capital and on the north during the Spanish Civil War. Although initially successful, the Republicans were forced to retreat from Brunete and suffered devastating casualties from the battle.

In early July, despite the earlier loss at the Battle of Bilbao, the government launched a strong counter-offensive to the west of Madrid, focusing on Brunete. The Battle of Bilbao was part of the War in the North, during the Spanish Civil War where the Nationalist Army captured the city of Bilbao and the remaining parts of the Basque Country still held by the Republic.

Franco invaded Aragón and took the city of Santander in Cantabria in August.

A Republican offensive against Zaragoza was also a failure. Despite having land and aerial advantages, the Battle of Belchite, a place lacking any military interest, resulted in an advance of only 10 kilometres (6.2 mi) and the loss of much equipment. The Battle of Belchite refers to a series of military operations that took place between 24 August and 7 September 1937, in and around the small town of Belchite, in Aragon during the Spanish Civil War.

With the surrender of the Republican army in the Basque territory came the Santoña Agreement. The Santoña Agreement, or Pact of Santoña, was an agreement signed in the town of Guriezo, near Santoña, Cantabria, on August 24, 1937, during the Spanish Civil War, between politicians close to the Basque Nationalist Party (Partido Nacionalista Vasco or PNV), fighting for the Spanish Republicans, and Italian forces, fighting for Francisco Franco.

Gijón finally fell in late October in the Asturias Offensive. The Asturias Offensive was an offensive in Asturias during the Spanish Civil War which lasted from 1 September to 21 October 1937. 45,000 men of the Spanish Republican Army met 90,000 men of the Nationalist forces.

The Battle of Teruel was an important confrontation. The city, which had formerly belonged to the Nationalists, was conquered by Republicans in January. The Francoist troops launched an offensive and recovered the city by 22 February, but Franco was forced to rely heavily on German and Italian air support. The Battle of Teruel was fought in and around the city of Teruel during the Spanish Civil War. The combatants fought the battle between December 1937 and February 1938, during the worst Spanish winter in twenty years. The battle was one of the bloodier actions of the war with the city changing hands several times, first falling to the Republicans and eventually being re-taken by the Nationalists. In the course of the fighting, Teruel was subjected to heavy artillery and aerial bombardment. The two sides suffered over 140,000 casualties between them in the two-month battle. It was a decisive battle of the war, as Francisco Franco's use of his superiority in men and material in regaining Teruel made it the military turning point of the war.

Tarragona fell on 15 January.

Barcelona fell on 26 January.

Girona fell on 2 February.

On 27 February, the United Kingdom and France recognized the Franco regime.

On 7 March, Nationalists launched the Aragon Offensive, and by 14 April they had pushed through to the Mediterranean, cutting the Republican-held portion of Spain in two. The Republican government attempted to sue for peace in May, but Franco demanded unconditional surrender, and the war raged on. In July, the Nationalist army pressed southward from Teruel and south along the coast toward the capital of the Republic at Valencia, but was halted in heavy fighting along the XYZ Line, a system of fortifications defending Valencia.

The Republican government then launched an all-out campaign to reconnect their territory in the Battle of the Ebro, from 24 July until 26 November, where Franco personally took command.

In 1938, Franco feared an immediate French intervention against a potential Nationalist victory in Spain through French occupation of Catalonia, the Balearic Islands, and Spanish Morocco.

Franco's troops conquered Catalonia in a whirlwind campaign during the first two months of 1939.

Only Madrid and a few other strongholds remained for the Republican forces. On 5 March 1939 the Republican army, led by the Colonel Segismundo Casado and the politician Julián Besteiro, rose against the prime minister Juan Negrín and formed the National Defence Council (Consejo Nacional de Defensa or CND) to negotiate a peace deal.

Negrín fled to France on 6 March, but the Communist troops around Madrid rose against the junta, starting a brief civil war within the civil war. Casado defeated them, and began peace negotiations with the Nationalists, but Franco refused to accept anything less than unconditional surrender.

On 26 March, the Nationalists started a general offensive.

On 28 March the Nationalists occupied Madrid and, by 31 March, they controlled all Spanish territory.

Franco proclaimed victory in a radio speech aired on 1 April, when the last of the Republican forces surrendered.

After the end of the war, there were harsh reprisals against Franco's former enemies. Thousands of Republicans were imprisoned and at least 30,000 executed. Other estimates of these deaths range from 50,000 to 200,000, depending on which deaths are included. Many others were put to forced labor, building railways, draining swamps, and digging canals.