Blood types are determined by instructions given on a person's DNA. If a person has instructions for Type A blood, the blood cell membranes will include a certain A type protein within them. As the person develops, that particular protein will be accepted as "self" and that protein will never be attacked by that person's immune system. It is as if the cell places a little identification flag on each blood cell, telling the body not to attack it. The body does not lock in what it will call "self" until about the age of six months. After this time, any protein that was not included in the body's "self" list will be attacked as an intruder.
People with Type B blood have a B type protein encoded for on their DNA and, therefore, have B proteins embedded in the membranes of their blood cells. Type AB blood cells have both A and B proteins. Type O blood cells have neither A nor B proteins.
This explains why only certain types of blood can be given to certain blood-type people. An individual with Type A blood can take both Types A and O. The immune system will not attack the A protein on the donor Type A because it recognizes it as "self". The Type O blood is accepted because it has no non-self proteins to act as antigens. Type B individuals can take either Type B or Type O from a donor. The B protein in the donor blood is accepted as self and the Type O blood, once again, has no antigens in it to react to. The fortunate people with Type AB have both A and B proteins listed as self. They will be allowed by their immune systems to accept Type A, Type B, Type AB and Type O because there are no proteins that are not on their self list. The unfortunate Type O person can only accept Type O blood because none of the other proteins (A and B) are listed as self.
The same is true for the Rh factor. If a person is positive for Rh, that means they have an extra protein antigen that is counted as self. A person with Rh negative blood does not have that protein on their self list and if they are given blood with that positive protein, it will be attacked as an intruder and destroyed. An Rh positive person can accept either Rh positive or negative blood without any harm. An Rh negative person can only accept Rh negative blood.
If an Rh negative mother becomes pregnant with an Rh positive child, there can be interchange between the child's blood and the mother's blood, especially during birth. This will cause the mother to develop antibodies to the Rh factor in the child's blood. This usually causes no harm during the first pregnancy, but it will set up the mother's immune system for a complete attack on a second Rh positive pregnancy. Medications can be given to stop this attack if blood tests show the mother has a high titer reaction to the Rh positive antigen.