For example, a single individual alive today would, over 30 generations going back to the High Middle Ages, have 230 or roughly 1 billion ancestors, more than the total world population at the time.
This may have been to keep kin bonds, wealth and property within a family (endogamy) or simply because there was a limited number of potential marriage partners available.
Essentially, Alfonso's parents were double first cousins, i.e. his two grandfathers were brothers and his two grandmothers were sisters, meaning there were only two sets of great-grandparents rather than four.
In the case of Charles II, the last Habsburg King of Spain, there were three uncle-niece marriages among the seven unions of his immediate ancestry (i.e. parents, grandparents and great-grandparents).
The maximum pedigree collapse of 50% within a single generation is caused by procreation between full siblings; such children have only two different grandparents instead of the usual four.
Even in America around the 19th century, the tendency of immigrants to marry among their ethnic, language or cultural group produced many cousin marriages.