system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How do your white blood cells know what's safe and how do they "learn" a disease to make you immune to it from then on by "recognizing" it?
gpt
The immune system is really complicated, so this is going to be a case where ELI5 is aiming for "true enough".

At the molecular level, cell membranes aren't smooth and featureless.  They have inlets and outlets, and various proteins attached to them.  The combination of these proteins can identify what species the cell is - kind of like a uniform identifying what army a soldier is a part of.   This is related to blood types by the way - there's different versions of the "Human" uniform, and your immune system will recognize other versions as foreign cells.  

Your immune system recognizes a uniform with its own proteins that float through your blood and lymph system.  Those proteins have ends like puzzle pieces, that only stick on to one particular protein that's not part of your body's uniform.  The white blood cells can detect the other end of those proteins, and treat it as a big sign saying "eat that thing".  

Those proteins are produced in several glands throughout your body.  The glands contain some cells that are rapidly mutating, coming up with new versions of those proteins.  Your body is able to recognize when one of those cells comes up with a protein that identifies something new, and allows that cell to reproduce.  Now that your body can identify the infection, you can fight it off, and in the future, if you contract it again your white blood cells will be able to find and eat it immediately.