How Spanish surnames began
Spanish surnames grew from the medieval kingdoms of the Iberian Peninsula. Patronymic names ending in "-ez" (son of) — González, Rodríguez, Fernández, López, Martínez — are by far the most common, alongside names from places, landscape features and nicknames.
Through Spain's empire these names spread across Latin America, the Philippines and the southern United States, and today Spanish surnames are carried by hundreds of millions of people.
How the names work
In Spain and most of Latin America every person has two surnames: the father's first surname followed by the mother's first surname, so the son of Juan García López and María Pérez Ruiz is García Pérez. Women keep their surnames after marriage. Since 1999 Spanish law has allowed parents to choose to put the mother's surname first. "de" or "y" sometimes joins the two surnames.