How do college credits work?

I have one son at a California UC that got 32 credits due to his AP classes/test scores, but they only went to elective credits and did not get him out of any major related classes.
My other son is at a California State University (CSU), he got 38 units of credit and he was able to opt out of 5 classes (2 major requirements) and 3 (GE Requirements).

Again as everyone as stated, it will depend upon the school(s).