You can imagine the immune system as a network of sentries communicating with each other in all possible places in the body. There is our skin with its acid mantle and the mucous membranes. These represent the first solid barrier for pathogens from outside. For example, there are mucous membranes with cilia everywhere in the respiratory tract and the gastrointestinal tract.
If something that is considered a nuisance enters, these membranes form a film of mucus to flush the pathogen out of the organism, for example through a cold. If the immune system is not successful in this, it activates another form of protection: phagocytes from the lymphatic system and white blood cells attack the foreign bacteria, viruses or fungi to render them harmless. This is also referred to as the "non-specific immune defense."
If this is also unsuccessful, the "specific immune defense" kicks in. This refers to the lymphocytes, a subgroup of white blood cells (leukocytes). They are "imprinted" in the bone marrow, spleen, thymus and lymph nodes, which means that they "learn" there which substances belong to the organism and which do not. While the non-specific defense is innate, the specific immune defense is based on previous contact with pathogens, which are now immediately recognized as harmful and fought.