17th century European noble culture commonly matched cousin to first cousin and uncle to niece, to preserve a prosperous family\’s properties. Charles\’s own immediate pedigree was exceptionally populated with nieces giving birth to children of their uncles: Charles\’s mother was a niece of Charles\’s father, being a daughter of Maria Anna of Spain (1606–46) and Emperor Ferdinand III. Thus, Empress Maria Anna was simultaneously his aunt and grandmother and Margarita of Austria was both his grandmother and great-grandmother. This inbreeding had given many in the family hereditary weaknesses. That Habsburg generation was more prone to still-births than were peasants in Spanish villages.
There was also insanity in Charles\’s family; his great-great-great(-great-great, depending along which lineage one counts) grandmother, Joanna of Castile (\”Joanna the Mad\”; however, the degree to which her \”madness\” was induced by circumstances of her confinement and political intrigues targeting her is debated), mother of the Spanish King Charles I (who was also Holy Roman Emperor Charles V) became insane early in life. Joanna was two of Charles\’ 16 great-great-great-grandmothers, six of his 32 great-great-great-great-grandmothers, and six of his 64 great-great-great-great-great-grandmothers.
Dating to approximately the year 1550, outbreeding in Charles II\’s lineage had ceased (see also pedigree collapse). From then on, all his ancestors were in one way or another descendants of Joanna the Mad and Philip I of Castile, and among these just the royal houses of Spain, Austria and Bavaria. Charles II\’s genome was actually more homozygous than that of an average child whose parents are siblings.