Before the introduction of the rojigualda (the current flag), the flag representing the whole of Spain was the Burgundy Cross, which dates back to 1506, when the marriage between Philip the Beautiful and Joan I of Castile was celebrated. This flag had a white background and a red St. Andrew's Cross. The Burgundy Cross remained the national flag of Spain until 1793 and continued to be used as the flag of the empire until 1898.
The current Spanish flag is derived from the naval flag used in the 18th century, during the reign of Charles III. The king announced a competition to choose a new design that would be more visible at sea, and the winner was the design submitted by Antonio Valdes y Fernández Bazán, Minister of the Navy. The flag consisted of two red stripes and a yellow stripe with the coats of arms of Castile and Leon, Granada, Aragon, Navarre, and the Two Sicilies.

In the 19th century, Spain went through a series of political and social changes. One of the most significant moments occurred during the First Spanish Republic (1873-1874), when an attempt was made to replace the rojigualda. However, it survived these changes and remained a symbol of the Spanish nation.
During the Civil War (1936-1939), Franco's army used the rojigualda as the official flag, adding an eagle after the victory. During Franco's dictatorship (1938-1975), the flag underwent changes in the form of the coat of arms and remained in use even after his death in 1975, during the first years of democratic transformation in Spain, with some changes, until 1981.

The modern version of the Spanish flag was approved by the 1978 Constitution, which marked the return to democracy in Spain after decades of dictatorship. It consists of three horizontal stripes: red, yellow (twice as wide as the other two) and red. On the yellow stripe is the national coat of arms. This coat of arms includes the royal seal between two crowned columns known as the Pillars of Hercules, with the inscription "Plus Ultra". The exact location and proportions of the coat of arms on the flag were later defined in a 1981 law.