The United States has entered into agreements, called Totalization Agreements, with several nations for the purpose of avoiding double taxation of income with respect to social security taxes. These agreements must be taken into account when determining whether any alien is subject to the U.S. Social Security/Medicare tax, or whether any U.S. citizen or resident alien is subject to the social security taxes of a foreign country. As of this time, Spain has entered into Totalization Agreement with the United States.
SSA Publication No. 05-10188, November 2005, ICN 480192 [OMB Approval Number: 0960-0554 Expires 12/31/2016] http://www.ssa.gov/international/Agreement_Pamphlets/spain.html