The Spanish royal collection of art was almost entirely built up by the monarchs of the Habsburg family who ruled Spain from 1516 to 1700, and then the Bourbons (1700–1868, with a brief interruption).  They included a number of kings with a serious interest in the arts, who were patrons of a series of major artists:  Charles V and Philip II were patrons of Titian, Philip IV appointed Velázquez as court painter, and Goya had a similar role at the court of Charles IV. 
 The royal family were the most important patrons of Spanish art throughout this period, although some important artists including El Greco, Jusepe de Ribera, and Zurbaran were little patronised.  Foreign artists were often imported, although even in the 16th century the most successful were often reluctant to go to Spain, partly because they feared they would never be allowed to leave.  In addition, at various periods, especially in the 16th and 17th centuries, the monarchs bought paintings abroad on a significant scale, especially in Italy, but also the Spanish Netherlands and France.  In early periods the scattered Spanish possessions included the important artistic centres of Milan, Naples, and the Low Countries.   
 With the loss of the Low Countries as a result of the Peace of Utrecht, the Spanish crown developed tapestry manufacture in Madrid to avoid the need for imports of these luxury items. As a young man, Goya executed a number of tapestry designs for use in the royal palaces. Royal patronage was also used to develop other arts and crafts in Spain in the 18th century, for example the Real Fábrica de Cristales de La Granja produced luxury glass products.
 The enormous collections have been significantly reduced by a series of fires, losses in the Napoleonic Wars and to a lesser extent the Spanish Civil War, and diplomatic gifts. The collections have passed to public ownership, and a large number are on display at various locations.  Although the collection is rightly most famous for its paintings, with the Prado in Madrid holding the main collection, there are large holdings of sculpture, and most forms of the decorative arts. What is probably the world's finest collection of Renaissance Flemish tapestries is mostly displayed at the Palace of La Granja, and the collection of plate armour in the Armoury in the Royal Palace, Madrid is only rivalled by its equivalent in Vienna.   
 Few Spanish paintings are recorded in the collection that were owned before the Habsburg reigns.  The c. 300 paintings owned by Isabella I of Castile (d. 1504) were dispersed in an auction after her death, with the paintings fetching very low prices compared to the many tapestries or her jewels and even clothes.  For example, a painting by Hieronymus Bosch was valued at 170 maravedis, but a tapestry of Lazarus at 150,000.  Some pieces were bought by the family, but her husband Ferdinand was mainly interested in the tapestries, paying 524,072 for two sets of four each, and buying the Lazarus piece at a lower price.  Isabella's son-in-law Philip the Handsome (Charles V's father) bought the Polyptych of Isabella of Castille a set of small religious paintings by  Juan de Flandes that have mostly remained in the royal collection (now Royal Palace).  Juan was court painter for Isabella I of Castile from 1496, but all of his paintings in the Prado collection were acquired in the 20th century,
 The collection includes those parts taken to Spain in the 16th century of the collection of the Valois Dukes of Bugundy, whose heir was Charles V. The Early Netherlandish paintings were further reinforced in 1558 on the death of Charles V's sister, Mary of Hungary, shortly after her retirement as governor of the Netherlands.  She was a keen collector whose heir was Philip II.  Her legacy included the Deposition of Christ by Rogier van der Weyden (Prado), by then over a century old.  She also had two dozen Titians.  Charles V was also the heir of his great-aunt Margaret of Austria (d. 1530), also governor of the Netherlands and a keen collector, though mostly of contemporary Netherlandish paintings. Her collection included the Arnolfini Portrait by Jan van Eyck, which left the collection in the Napoleonic Wars and is now in the National Gallery, London.
 All of these additions from the Low Countries were probably valued more for their tapestries than their paintings. Charles V spent more on tapestries than paintings (like his contemporary Henry VIII), and commissioned them throughout his life, continuing the family tradition, and reflecting common royal preferences at the time.   
 The largely German collections of Charles' grandfather Maximilian I, Holy Roman Emperor and the earlier Habsburgs mostly remained in Austria and Germany when in 1556 Charles V abdicated and divided his enormous realms between his brother, who became Ferdinand I, Holy Roman Emperor, and his son Philip, who received Spain, the Netherlands and the Habsburg possessions in Italy.  They are now in the Kunsthistorisches Museum, Vienna, and elsewhere. 
 Charles V was also a keen and discriminating collector, and his relentless travelling made him aware of the diversity of Renaissance art, above all that of Italy.  He was greatly impressed by a Titian portrait of the Duke of Mantua and his dog (c. 1529, Prado), and arranged for Titian to paint him, in Bologna in 1532, full-length and also with a hound (Prado).  This was a repetition of a recent portrait (Vienna) by his brother's court painter Jakob Seisenegger, intended as a demonstration piece. This fully won Charles over, and from then on he never posed for any other portrait painter, as Vasari says, despite the difficulties in meeting Titian to pose.  His Equestrian Portrait of Charles V (Prado) set the standard for the genre, influencing later artists such as Anthony van Dyck, Rubens, and Goya.  But the Milan-based sculptor Leone Leoni, assisted by his son Pompeo, occupied from 1546 an equivalent position in sculpture; there are full and half-length bronze portrait sculptures of Charles in the Prado, as well as medals and engraved gems. The Dutch painter Jan Cornelisz Vermeyen was mostly used to record Charles's military victories, especially in designs for large tapestries, and Charles took him on his campaign to Tunis.
 Charles's son Philip II of Spain (reigned 1556 to 1598) was devoted to his father's memory, and probably more interested in art than his father; certainly he commissioned and bought much more, and by the end of his life the collection included some 1,500 paintings, and about 700 tapestries.  He took over Charles's key artists, Titian and the Leonis, and commissioned the famous and now dispersed series of mythological paintings known as the poesie, which represent some of his finest late works.  Of these six or seven paintings, only one at most of the prime versions remained in the collection until transfer to the Prado; five are now in the United Kingdom, and one in the United States. 
 In 1561 Philip established Madrid as the capital of Spain, something his father had planned but never implemented.  He also began to construct a massive monument to his father and the other Spanish Habsburgs at El Escorial, whose building and decoration was to be the major artistic project of his reign.
 Philip III of Spain, who reigned from 1598 to 1621, continued the output of royal portraits, but otherwise was not greatly interested in art. Arguably, his reign was in any case an unremarkable period in Spanish painting. He commissioned an equestrian statue of himself by Giambologna, who did not visit Spain in person. Rubens came as an ambassador, and painted his valido (chief minister and favourite) the Duke of Lerma, but not the royal family. 
 In great contrast to his father, the long reign of Philip IV of Spain (1621-1665) saw great personal involvement by the monarch in artistic patronage. Diego Velázquez (1599-1660) was brought to the king's attention when still young, after the death of Rodrigo de Villandrando in 1622, and remained in royal service for the rest of his life, also progressing through the hierarchy of courtiers. Philip enjoyed his company, and often came to see him paint. The very informal Las Meninas show the artist painting the king and queen, with their daughter watching. 
 Velázquez was twice given permission to visit Italy, in 1629-30 and 1649-51. On the second visit he was used as a agent of the king to buy art, which he did on a large scale, with excellent judgement.
 Charles II of Spain's reign (1661-1700) saw Spain's decline become evident. Royal patronage of official portraits continued, but there was relatively little other than that, and the receipt of diplomatic gifts from other monarchs.  Court painters included Juan Carreño de Miranda.
 After Charles' death, the War of the Spanish Succession from 1701 to 1715 disrupted royal patronage, especially in the early years. The new king, Philip V, was a young French prince, whose reign lasted, with a brief interruption, from 1700 to 1746. French portrait painters were now used heavily, including Jean Ranc and Louis-Michel van Loo, who replaced Ranc as the main court portraitist from 1736, and native Spanish painters like Miguel Jacinto Meléndez needed to adjust their style.  
 Van Loo remained in place in the reign of Philip's son Ferdinand VI (r. 1746-1759), until he returned to Paris in 1753. 
 Reigning over Spain from 1759 to 1788, Charles III was considerably more capable and dynamic than his predecessors for a century before.  He had also trained in painting and etching when young (it was a French custom for princes to learn a manual trade) and continued to etch in later life. He twice persuaded Anton Raphael Mengs (d. 1779), the leading painter of Neoclassicism, the avant-garde movement of the day to leave Rome to visit Spain, which successful artists were traditionally reluctant to do. As well as a large ceiling in the Royal Palace of Madrid, several portraits of the royal family remain in the collection. 
 Mengs was a bitter rival of Giovanni Battista Tiepolo, from a generation earlier. He spent his last years in Madrid, from 1761 to 1770, painting three ceilings in the Royal Palace, and a set of paintings for a church, which were quickly replaced by works by Mengs after court intrigues, apparently reflecting the king's taste. One, The Immaculate Conception reached the Prado in 1827.
 Francisco Bayeu y Subías was an assistant to and protege of Mengs from 1763, who was given a job designing for the Royal Tapestry Factory the same year, becoming director in 1777.  Francisco Goya had been a pupil of Mengs in the 1760s, but they had not got on. After a trip to Italy he got on much better with Bayeu, and in 1773 married his sister Josefa. When he became director Bayeu employed Goya to design tapestries, with about 50 of his painted cartoons remaining in the collection, as well as most of the tapestries made from them.
 In the 1780s Goya began to paint portraits of the court, including the king. He began with a portrait of José Moñino, 1st Count of Floridablanca, Charles's chief minister, in 1783 (Prado), and then painted many of the family of Charles's brother Infante Luis of Spain. In 1786 he was made a salaried court painter.
 Goya's position was confirmed by  Charles IV and in 1790 he was promoted to First Court Painter. Ill-health, changing artistic inspiration and finally the French invasion of 1808 made his work for the court tail off, but his Charles IV of Spain and His Family (1800-01) is one of the most admired portraits in the Prado.  Other works not commissioned by the king reached the Prado later, including La maja desnuda (1790s) and La maja vestida (1800s), and the late Black Paintings.   
 Though the collection continued to gain paintings from royal commissions after the Restoration, and to acquire older works, the great days of royal patronage culminated with Goya.
 In June 1561 Philip II set his court in Madrid, installing it in the Alcázar, which became home to a huge art collection.
The monarchy continued to use other palaces. A new palace was begun in 1563 when the corner-stone was laid of El Escorial, a combined monastery and palace in the mountains to the north of the capital.
 In 1734 the Alcázar was destroyed by fire along with many works of art. 
 Many of the finest paintings from the former Spanish royal collection are housed in the Museo del Prado, Spain's national art museum. This institution was opened to the public as an art gallery in 1819 in an initiative associated with Queen Maria Isabel. Having been a royal museum  (Museo real de pinturas), the Prado was nationalised in 1868 as a consequence of the deposition of Queen Isabel II. Although the First Spanish Republic of the 1870s was of short duration and Spain returned to being a monarchy, the collection has remained a national rather than a royal collection.
 To mark the 200th anniversary of the Prado, the Hall of Realms, a surviving 17th-century wing of the Buen Retiro Palace, is being redeveloped as part of the campus of the museum. Originally, the Hall housed large paintings from the royal collection. Some of these, such as equestrian portraits of the family of Philip IV, are now in the Prado. While in theory these paintings could be restored to their original location, this would disrupt the layout of key galleries of the Prado, and other uses are currently envisaged for the Hall of Realms.
 The heritage agency Patrimonio Nacional looks after a number of royal sites in Spain and the art works in them. 
The Palacio Real contains numerous artworks including frescoes by Tiepolo and a unique set of Stradivarius instruments known as the Stradivarius Palatinos.
A new museum in Madrid, the Royal Collections Gallery, opened in 2023 on a site near the Palacio Real and the Royal Armoury.  Built in order to display material from the royal collections which is in the care of Patrimonio Nacional, the new museum is intended to be complementary to the other two buildings, so that they are arguably comparable to the triangle of art of the Paseo del Prado. 
The chronological framework of the new museum is from the Middle Ages to the reign of Juan Carlos I.
 Patrimonio Nacional has a tradition of organising temporary exhibitions, for example in 2019 it mounted an exhibition about Alfonso XIII's humanitarian intervention in the First World War. It expects to change regularly the exhibits in the new museum.
 In 1604 much of the secondary royal palace of El Pardo, then just outside Madrid, was destroyed in a fire.  Many paintings were rescued, but the group of important royal portraits by Titian and others in the "Hall of Kings" were mounted on the walls by stucco frames, and could not be taken out in time.  Philip III ordered the room to be reconstituted, with Juan Pantoja de la Cruz set to producing new versions of the paintings from the sources available to him.
 The Torre de la Parada, then just north of Madrid, was a large hunting lodge started by Charles V and greatly expanded by Philip IV.  As such the extreme formality of the main royal palaces was relaxed there.  The relatively informal Velázquez royal portraits in hunting clothes, and mock-heroic portraits of court dwarves and jesters, were painted for it, and also a huge series of 60 mythological subjects by Rubens and his workshop, from which 40 of the paintings and over 50 of Rubens' oil sketches survive (Prado). The palace was mostly destroyed by fire when taken in 1714 by Austrian troops in the War of Spanish Succession, remaining only as ruins.  But much of the portable art had already been removed to other palaces.
 The first main home of the collection, the Alcázar of Madrid, was completely destroyed by fire in 1734, with great losses.  Some paintings, such as Las Meninas were rescued, in that case by cutting it from its frame and dropping it out of a window.  Some paintings had already been installed in the Buen Retiro Palace on the other side of the city centre.
 The Spanish Habsburgs ruled Portugal from 1581 to 1640 (under Philips II to IV), and Philip II in particular gave the main Lisbon residence the Ribeira Palace much art, including a large ceiling by Titian.  This and most of its other art was lost in the 1755 Lisbon earthquake which largely destroyed the palace. 
 Some 80 paintings from the former Spanish royal collection are in the Wellington Collection in London. These were being taken from Spain by the French when they were captured by the British army at the Battle of Vitoria. They were subsequently gifted to the British general Arthur Wellesley, 1st Duke of Wellington by Fernando VII, and are kept at Apsley House, the London home of the Dukes of Wellington, where they are mainly on public display.