The role of the immune system is to protect our body from any foreign matters that might cause any damage or homeostatis imbalance. The success of the immune system depends on its ability to discriminate between foreign(non self) and host(self) cells. When an organism is threatened by microorganisms, viruses, or cancer cells, the immune system acts to provide protection. Normally the immune system does not mount a response against self. This lack of an immune response is called tolerance.
When a foreign matter enters the human body, our defense system recognizes this as foreign through the immune system. How the human body recognize foreign against itself employs a complex "I.D." system. Each cell in the human body carries on it's surface a mixture of proteins and sugars that serve to idenify the cell to the immune system. Foreign objects lack the idenifiers that all of the body's cells have, but each one has unique features or antigens where the immune system attachs idenifiers called antibodies. This is the basis for the specific defense mechanisms, once you have built the antibodies for a specific antigen the immune system will respond faster than if the had been no previous exposure to the antigen (i.e. you are immune to the pathogen, but only that specific pathogen, because your immune sytem responds faster.) The non-specific part of the immune system is mostly composed of phagocytes (eating-cells) which engulf and digest foreign substances like bacteria and viruses, which do not bear the body's specifc idenifers.