The decline of the Spanish empire was brought about by many factors. Money was tight for the Spanish during the 17th century, despite that galleons filled with gold were sent from the Americas (though many were raided by pirates or were wrecked in storms). But conquering and forming an empire is one thing; maintaining it quite another. Often the natives of a conquered land are not happy with the conditions they're subjected to by the conquerors, just as often those conditions are brutal and unfair. So they rise up in arms, and that means that empire has to spend a lot of money on armies and weapons to extinguish it.
This is more or less what happened when the Dutch revolt, which finished during the 17th century. The Spanish colonies in the Netherlands rose because their Spanish rulers were not really interested in their needs and didn't solve any of their problems. Besides Calvinism was starting to spread like fire on hay and the Spanish were not only Catholic, but liked everybody in their territories to be Catholic as well.
The Dutch didn't exactly get their independence right away, but the way was paved. After the revolt a 12 year truce ensued, but as soon as Spain felt ready it attacked again, without much success. But war, beside expensive, is unpredictable. Who knows what might have happened if the French hadn't got involved? France and Spain had a strong mutual hatred and the French would befriend any of Spain's enemies. It became more of a war between France and Spain. Spain lost the war and territories and the right to be called a world power, bringing about the decline of the Spanish empire which the Anglo Spanish war helped cement.
On the home front things weren't going so great either. There were several revolts, including the Catalan revolt and the the Basque revolt among others, when the Count Duke of Olivares proposed raising taxes. For whatever reason the King relied completely a man with a record for causing trouble (his decisions had lead to the war with the Dutch and later France).
The last stroke would come from their neighbours. For some time now, Spain and Portugal had been joined in the Iberian Union, under Spanish rule. However when the Portuguese nobility began to lose their influence and power, when the Cortes and Portuguese posts were being occupied by the high Spanish classes, and when the taxes were raised by the Count Duke of Olivares, the Portuguese had had enough. How did they show their displeasure? By crowning their own king and expelling the Spanish from their country. They also befriended one of Spain's biggest enemies, England. In the end Spain was forced to recognize the Portuguese independence.