When a pathogen invades the body, B cells recognize specific antigens on the surface of the pathogen. This recognition triggers the B cells to differentiate into plasma cells and memory B cells. Plasma cells produce large amounts of antibodies, while memory B cells remain in the body to provide a quicker response if the same pathogen is encountered again.