A well-functioning immune system is key to providing good defence against pathogenic organisms and to providing tolerance to non-threatening organisms, to food components and to self. The immune system works by providing an exclusion barrier, by identifying and eliminating pathogens and by identifying and tolerating non-threatening sources of antigens, and by maintaining a memory of immunological encounters. The immune system is complex involving many different cell types distributed throughout the body and many different chemical mediators some of which are involved directly in defence while others have a regulatory role. Babies are born with an immature immune system that fully develops in the first few years of life. Immune competence can decline with ageing. The sub-optimal immune competence that occurs early and late in life increases susceptibility to infection. Undernutrition decreases immune defences, making an individual more susceptible to infection. However, the immune response to an infection can itself impair nutritional status and alter body composition. Practically all forms of immunity are affected by protein–energy malnutrition, but non-specific defences and cell-mediated immunity are most severely affected. Micronutrient deficiencies impair immune function. Here, vitamins A, D and E, and Zn, Fe and Se are discussed. The gut-associated lymphoid tissue is especially important in health and well-being because of its close proximity to a large and diverse population of organisms in the gastrointestinal tract and its exposure to food constituents. Certain probiotic bacteria which modify the gut microbiota enhance immune function in laboratory animals and may do so in human subjects.