Good question, and I hope my previous answer is useful.
To talk about Spain in the 19th century, we must talk about Spain in the 17th century. That is the period many agree is the beginning of the decline. And to talk about Spain's decline we must also talk about Spain's rise to become a European and global power in the 16th century.
Habsburg Spain
The Spanish empire of the 16th century happened mostly through inheritance, something already covered in several threads here.
To summarize, Charles V inherited separate lands, and separate kingdoms/counties/duchies in Spain, Burgundy, Low Countries, Italy, Austria and Germany. Spain still consisted of several kingdoms, each with its own rules: Castille and Leon, Aragon, Navarre. Castille had the most developed taxation system. Aragon was stagnating, Navarre was a new acquisition. Charles V put significant effort in extracting further revenue from Castille to finance his needs and commitments elsewhere. By contrast, he didn't put nearly as much effort with Aragon/Catalonia and Navarre.
Using Castille's reliable tax base, Charles borrowed huge sums of money from German bankers as he dealt with one crisis and another.
The Casa de Contratación continued to control the Atlantic trade via Seville, and operated exclusively. Throughout the reign of the Habsburgs, Spain's colonies in the Americas were limited to sailing only to or from Seville. Inter-colonies trade was not allowed. The manufacture of many basic and important sailing equipment was not allowed, the colonies had to purchase all these from Spain. The Casa de Contratación collected taxes, and it alone approved trades and explorations. It also maintained all the navigational maps and secret information.
Despite Charles V's earlier wish to pass on his entire set of possessions to his son Philip II, he was opposed by his brother Ferdinand, who acted as his regent in Austria, the HRE, and Hungary. As a result, the Habsburg inheritance had to be divided.
Philip II inherited Spain's kingdoms, Italian lands and Balearic islands via Aragon, and Burgundy and the Low Countries. As he approached retirement, Charles V had cultivated a northwestern orbit between Spain, England (as Philip II was married to Mary Tudor), the Low Countries. However, as we know Elizabeth succeeded Mary Tudor and brought England away to eventually become an enemy of Spain. This made his efforts in the Low Countries more difficult and much more expensive, such that he declared bankruptcy multiple times. This, and inflations, means that Castille's artisan class couldn't develop and it remained a raw materials producer.
In the Mediterranean he had to contend with the rise of the Ottomans and their allies Barbary pirates. This means more expenses, reliance of Genoese navies and monies, just to maintain the link between continental Spain, the Balearic islands, Sicily, Naples. Because Castille was the cash cow, it was made to focus on sheep herding at the cost of crops, and Spain had to rely on Balearic islands and Sicily for grain shipments.
Philip IV relied on "favorites" such as Lerma and Olivares. While they had ideas of uniting the various kingdoms under a stronger central government, their efforts failed due to corruption and internal weaknesses. When Olivares asked for Catalonia to contribute troops, funds, and housing for troops in the Pyreneean border. Unhappy, Catalonia rebelled. Sensing an opportunity, Portugal, who had been absorbed into a personal union under Philip II, also rebelled. The Thirty Years War and Eighty Years War saw Spain recognize the independence of the Netherlands in 1648.
Eventually, with Charles II the question of succession became paramount as he could not produce an offspring. The Bourbon candidate, descendant of Louis XIV, won the war of Spanish succession, ending the Habsburg line.
http://www.reddit.com/r/AskHistorians/comments/31zluu/the_decline_of_spain_in_the_16th18th_century/
At this point, it is important to quote J. H. Elliott's "Imperial Spain", which is that,
The reign of Charles V, in fact, saw three dangerous developments that were to be of incalculable importance for 16th and 17th century Spain. In the first place, it established the dominance of foreign bankers over the country's sources of wealth. Secondly, it determined that Castile would bear the main weight of the fiscal burden within Spain. In the third place, it ensured that within Castile the brunt of the burden was borne by those classes which were least capable of bearing it.
Bourbon Spain
Following his victory, the Bourbon Philip V was able to finally abolish several of the disparage states of Spain and further centralize power. Navarra, being an early supporter, was rewarded and was allowed to keep its fueros in name such that it had a degree of autonomy. However, it came with important concessions: Milan, Naples, Flanders, and Gibraltar were ceded. Yet there were still many structural problems. Spain still lacked a middle class. Even in shipbuilding they were considered weak. Capital was scarce, thanks to inflation and economic distress.
The Bourbon rulers of Spain instituted Bourbon reforms in the Americas to improve administration. They founded new viceroyalties, allowed each to raise and maintain a militia, and reduced the influence of the church. New trade routes were opened, where previously routes were tightly controlled. Licensed ships could trade freely in the Americas. The Navy was modernized, and shipyards expanded.
A new administration model in the Americas meant the Bourbons encouraged continental Spanish administrators to move to the Americas, at the cost of conflict with the rising criollos. They also moved the Casa de Contratación from Seville to Cadiz, as the Seville port suffered from the river silting, which in turn limited shipping and navigation.
However, as we know these reforms came too little too late. While the Americas rose in economic activity, so did racial tension. A Bourbon ruler meant a change of orbit from the Austrian Habsburg to the French Bourbons. This meant Spanish involvement on France's side in conflicts around the globe. Spain's entry to the Seven Years' war brought British attacks and occupation of the Philippines, Cuba, and Florida. While Spain re-gained some Italian possessions from the War of Austrian Succession, its overseas colonies were subjected to British attacks.
To summarize, Bourbon Spain partially improved the consolidation of its constituent Iberian kingdoms but never achieved the degree to which other nations succeeded (France, Great Britain, even Italy and Germany). Its foreign policy was often aligned with that of France, thus her colonies abroad were subjected to attacks by France's enemies. Deregulation of trade and new ruling system in the Americas led to greater independence and tension. Combined with misfortunes in European events such as the Napoleonic wars, this saw many colonies declare independence over time. Finally, long-term devastating wars related to liberal politics versus conservatives, made lasting impact on Spain even as it enters the 20th century.
Sources