In old times most people had just a first name for example Juan. When population started to grow around the XIII century it was necessary to differentiate between the several people with the same first name in the same town. Problem was solved by adding some description to the first name.
We can classify this description in four different types:
1 - Patronymic
Using the individual father’s name to differentiate two individuals. For example Juan son of Sancho (Juan Sanchez) compared to Juan son of Rodrigo (Juan Rodriguez). This was the most common way to differentiate and in Spain and Portugal, just adding “ez, es, iz” to present the father. We see the results today as they represent the most widespread Hispanic lastnames. For example: Álvarez, Benítez, Bermúdez, Díaz, Domínguez, Fernández, García, González, López, Martínez, Rodríguez, Sánchez and Velázquez.
2 - Related to occupation or title
The occupation of the individuals was also used to differentiate them. Juan the shoemaker (Juan Zapatero) compared to Juan the blacksmith (Juan Herrero).
Some examples are: Alcalde (mayor), Alférez (ensign), Alguacil (sheriff), Barbero (barber), Cardenal (cardinal), Carpintero (carpenter), Escribano (clerk), Escudero (squire), Herrero (smith), Jurado (jury), Labrador (farmer), Mesonero (innkeeper), Molinero (miller), Pastor (shepherd), Pescador (fisherman), Sacristán (sexton), Sastre (tailor), Zapatero (shoemaker).
Keep in mind the occupations or trades in old times were maintained in the family and passed from generation to generation. The son of the shoemaker almost certainly would be shoemaker and the same would happen with his own son.
3 - Descriptive
A physical characteristic or a nickname is used to differentiate two individuals. For example Juan the blonde (Juan Rubio) compared to Juan the fat (Juan Gordo).
Some examples of descriptive lastnames are: Alegre (cheerful), Barriga (belly), Bello (good looking), Blanco (white), Bravo (brave), Bueno (good), Calvo (bald), Cortés (polite), Crespo (curly), Delgado (thin), Leal (loyal), Manso (meek), Moreno (brown), Rubio (blonde).
4 - Geographic
Also known as toponymic, a geographic location or description is used to differentiate two individuals. For example Juan from the lake (Juan Lago) compared to Juan from the hill (Juan Cerro).
Some examples of geographic lastnames are: Cerro (hill), Costa (coast), Cuevas (cave), Lago (Lake), Montemayor (Highest Hill), Nieves (snow), Torres (tower).
Also under this classification we find all he lastnames that refer to know regions, cities or villages. For example: Aragonés, Asturias, Ávila, Burgos, Gallego, León, Navarro, Rivadavia, Villalobos, Villanueva, Zamorano
These four types of descriptions were used at the beginning for specific individuals and not the whole family. But at the end of the Middle Ages they became hereditary lastnames and that were passed from generation to generation getting to our current times.