Spain was not a bystander to the American Revolutionary War, although that fact is rarely mentioned in cursory historical surveys. Spain's motivation to help the American colonists was driven by a desire to regain the land it had lost to Britain and, with other European powers, make incremental gains against British possessions in other parts of the world. Although some dreamers in Spain perhaps envisioned its eventual possession of the entire New World, I have found no evidence that such an idea guided its assistance to the American colonists.
Spain was not a bystander to the American Revolutionary War
France and Spain were at that time both under Bourbon kings, Louis XVI and Carlos III, respectively, whose American possessions had been significantly reduced by the 1763 Treaty of Paris that ended the Seven Years' (the French and Indian) War. At the beginning of the American War of Independence, American commissioners were sent to Europe by the Continental Congress to seek support for their cause. John Jay, American representative in Spain, found success. Americans promised both France and Spain the restoration of much of the land they had lost to the British in America. In April 1779, Spain committed to helping the Americans.
Financial Support
This help did not consist of Spanish troops to fight alongside Americans, but it was extensive nevertheless. The Spanish and French kings provided large loans and outright contributions of money to the Americans. Spain laundered this money, as we would say today, through a fictitious private trading company, Roderique Hortalez and Company, operating out of the Lesser Antilles, which sent both money and war material directly to the Americans. The money helped support the Americans' new currency, the Continental, and also made it possible for the Americans to bring in foreign military officers, such as Augustus von Steuben, Casimir Pulaski, and Thaddeus Kosciuszko, to fight for them.
Land Battles
Spain began a military campaign of its own against the British in Florida and Louisiana. From 1779 through 1782, the Spanish Governor of Louisiana, Don Bernardo de Gàlvez, conducted a series of military actions against the British to retake forts that Spain had earlier lost to the British, succeeding in the Mississippi River Valley, and at Baton Rouge, Natchez, Mobile, and Pensacola. In 1782, Spain also succeeded in wresting back the Bahamas from the British.
Naval Support
A very substantial form of Spain's support for the Americans involved a strategy of joining Britain's other European competitors in tying up British naval resources by engaging them elsewhere than in Britain's American colonies. Spain did this, for example, against Gibraltar and Minorca, and together with France sent a fleet into the English Channel to menace the British coast and tie up more British ships. Most of the European maritime powers, including Spain, united against Britain's effort to interrupt their trade with America. With both France and Spain (and Holland) indirectly in the fray, Britain's navy was outmatched and could not effectively concentrate its military force in America. Spanish ships joined with French ships in the naval blockade of the British army at Yorktown in 1781, preventing General Cornwallis's resupply by the British navy, resulting in his surrender.