The naming tradition in Spain has always been very confusing for those of us from outside used to the simple Anglo-Saxon tradition.
Spaniards can have one or two given names (which would always be in composite form - there is no such thing as a middle name in Spanish) and two surnames. Under current law either surname can can come first; it is up to the individual to choose.
Traditionally though, the first apellido is the first surname of the father and the second the first surname of the mother. Surnames too can be composite linked by “de” (of) or a hyphen which makes for even more complications. For example a child could end up with a name like Juan Pablo Fernández de Calderón García-Iglesias. As you might imagine, having the same surname repeated is fairly common where the parents have the same surname so you get e.g. Moya Moya.
To make matters more confusing, Spanish women do not change their surnames at marriage. When marrying, a woman has the option of keeping all her names and adding her husband's last name or dropping her mother's maiden name. For their children though it is traditionally the father's, name that used to take priority whatever the mother decided to do.
Now, under a change in the law, unless the parents request otherwise, the surnames will be registered in alphabetical order.
A practical example:
Before our marriage my wife would have been Pamela Fenton Oliver and I would have been Keith Williamson Butterworth. Traditionally our children would take the name Williamson Fenton. But, under the new law, they would be Fenton Williamson unless we specified otherwise which would be important because when they married the first of the names would survive.