From early on in evolution, organisms have had to protect themselves from pathogens. Mechanisms for discriminating ''self'' from ''non-self'' evolved to accomplish this task, launching a long history of host-pathogen co-evolution. Evolution of mechanisms of immune defense has resulted in a variety of strategies. Even unicellular organisms have rich arsenals of mechanisms for protection, such as restriction endonucleases, antimicrobial peptides, and RNA interference.In multicellular organisms, specialized immune cells have evolved, capable of recognition, phagocytosis, and killing of foreign cells as well as removing their own cells changed by damage, senescence, infection, or cancer. Additional humoral factors, such as the complement cascade, have developed that co-operate with cellular immunity in fighting infection and maintaining homeostasis. Defensive mechanisms based on germline-encoded receptors constitute a system known as innate immunity. In jaw vertebrates, this system is supplemented with a second system, adaptive immunity, which in contrast to innate immunity is based on diversification of immune receptors and on immunological memory in each individual.Usually, each newly evolved defense mechanism did not replace the previous one, but supplemented it, resulting in a layered structure of the immune system. The immune system is not one system but rather a sophisticated network of various defensive mechanisms operating on different levels, ranging from mechanisms common for every cell in the body to specialized immune cells and responses at the level of the whole organism. Adaptive changes in pathogens have shaped the evolution of the immune system at all levels.