Though Spain is mostly known as a wine producing and consuming country, the truth is that beer is a very important beverage in the country as well. Like wine, beer is a fermented beverage so it is probably quite old as the technology for these kinds of drinks appeared very early. There are no certainties though as to who brought it to the peninsular. The formula may have been inherited from the Greeks or the Phoenicians who traded in the south of the country and some areas of the the Mediterrranean.
There are other theories that say it came with Lybian soldiers. Be it as it may, we have references from Pliny the Elder, who did not like beer from Hispania, that the Iberians drank far too much of it.
Unlike wine, Spanish beer went rather unnoticed in Europe for hundreds of years until emperor Charles V came to Spain from Flandes, brining with him his court and their strange customs. Charles was born in Ghentt in 1500. In time he would become the most powerful man in the world of his time, but as condition to access the Spanish crown, he must comply to learn Spanish and live in Castile. Flandes was not a wine producing country and therefore had quite a taste for beer, which the king imported to the Iberian country. The Charles hired a brewmaster from central Europe and installed a small beer factory in a monastery.
The Spanish beer factory was built next to the Manzanares' river bank due to the great quality of its water (the Spanish capital was Valladolid then, not Madrid by the way) and it functioned from 1537, manufacturing beer for the King, who liked to drink it ice cold, to his doctor's dismay, and it closed in 1558, when the king abdicated and retired to a monastery in Yuste (Cáceres).
However the king's taste for beer was not shared by the people, who hated him. His son and successor Philip II commanded the reestablishment of beer production in the riviera of the Manzanares, in this case Spain was the capital of Madrid, since the courts had been recently been transfered from Valladolid to the current capital. The number of large factories of Spanish beer varied from then on, but despite the fact that beer had no popularity to speak of, from then on there would always be beer production in Spain.
Still the commoners and gentry alike did not really have a taste for the golden beverage. Perhaps it really didn't have much to do with king Charles V at all, but rather the fact that wine in Spain was good and cheap.
Spanish beer factories in Madrid opened in 1611, most named after their owners, who were either Flemish, Alsacian or German, anything but Spanish. Soon some rules and regulations were made in regards to beer manufacture, among them the ingredients: wheat, barley and hop. If anything else was used the responsibles would suffer a penalty.
Even so, no one in Spain really liked beer and most references we find don't give any praise. Only during the beginning of the 20th century did it gain enough popularity for large factories to open. Mahou (Madrid) opened in 1890, Águila in 1900, Cruz del Campo (today Cruzcampo) in 1904 and Damm in 1910.
However the dice did turn and during the 60's it became the prefered summer drink for two reasons: it's low alcoholic content and that it was very refreshing. Unlike previous centuties, beer came to be cheaper than wine, perhaps this fact contributed to its increasing popularity.
Nowadays, beer is one of the drinks of choice when you head to a Spanish bar and can often be cheaper than most soft drinks! It is not uncommon for people to order a 'caña' which is a small glass of beer and then be served with a tapa as well. These small glasses of beer mean that you can drink the beer and it doesn't go warm by the time you get to the bottom as it might with a pint glass. It also means that is easier to hop from one bar to another as it doesn't take long to finish a caña. 'Cañas y tapas' is a great thing to do with your friends that you might meet in Spain.