It’s an easy way to figure people’s grandparents’ family name. In Spain, if you’re Luis Garcia Gutiérrez, it means your dad’s surname is Garcia (and hence his father’s surname too) — and your mother’s surname is Gutiérrez (and her father’s name too).
If you want to know the surnames of the grandmothers, add the your parents’ second surname:
Me: Luis Garcia (A) Gutiérrez (B)
Father: Name Garcia (A) Pérez (C)
Mother: Name Gutiérrez (B) Sánchez (D)
Father’s Father: Name García (A) Surname2
Father’s Mother: Name Pérez (C) Surname2
Mother’s Father: Name Gutiérrez (B) Surname2
Mother’s Mother: Name Sánchez (D) Surname2
Switch genders if you cross the border to Portugal.
It’s like the Scandinavian Farfar, Farmor, Morfar and Mormor... except it’s for everyone’s perspective, not just the grandchildren.