The flag of Spain, "La Rojigualda", took its present form in 1981. The red and yellow behind it are much older, and the coat of arms on the yellow band is a compressed history of the kingdoms that became Spain.
A naval solution that became a national flag
Charles III introduced the red and yellow in 1785 for a specific reason: Spanish naval flags were white with the royal arms, and at sea that made them hard to tell from several other European ensigns. He wanted a flag his ships could be recognized by. It worked well enough that the colors outlived the problem they were designed to solve.
After that the flag tracked Spanish politics closely. The Second Spanish Republic replaced the lower red band with purple in 1931. The monarchy's restoration in 1939 brought back red and yellow, though the coat of arms was reworked to suit the government of the day. Franco's death and the drafting of a new constitution in 1978 led to another revision, and the version adopted in 1981 is the one still flown.
The coat of arms
Two red stripes with a wider yellow one between them. Red is conventionally read as bravery and yellow as generosity, though the colors were chosen for visibility rather than symbolism.
The arms sit towards the hoist on the yellow band. The crowned shield is divided into six, with the quarters standing for Castile, León, Aragon, Navarre, and Granada, plus a small blue shield at the center bearing three fleurs-de-lis for the Bourbon dynasty. Flanking the shield are two columns, the Pillars of Hercules, carrying the motto "Plus Ultra", further beyond, a reference to Spanish expansion in the age of exploration. The crown above the shield marks the constitutional monarchy.
Flying it
The flag is displayed on government buildings, at embassies, and at royal events, and it is flown widely by the public on National Day, October 12, and at major sporting fixtures. Rules govern half-staff display during national mourning.
There are also maritime and military versions. The civil ensign, used by merchant shipping, drops the coat of arms and shows the colors alone; the naval ensign carries its own emblem.
Similar flags and influences
Aragon's flag uses red and yellow stripes, which is unsurprising given where the national colors are thought to have come from. Further afield, Venezuela and Colombia use horizontal stripe designs that carry traces of the Spanish colonial period.
What the flag argues about
The flag has never been politically neutral in Spain. It is used as a rallying symbol in demonstrations and political movements, and it recurs in arguments about national identity, particularly where regional nationalisms are strong. Being flown by one side of a dispute is not the same as being uncontroversial, and the Rojigualda has spent most of its life on one side or another.
References
[1] Spanish Government Official Publications: Spain's Flag Regulation and History (boe.es)
[2] Spanish Royal Decree on Flags (fomento.gob.es)
[3] Historical Records, Library of Congress (loc.gov)
[4] Encyclopaedia Britannica on Spain (britannica.com)