In the game of Nim, played with two players, if you have $n$ stacks of stones (where you can take any number of stones from a single pile each turn), losing positions are ones where the xor of the stack sizes equals 0.
I don't quite understand why this xor rule necessarily follows or why it is true.
The key properties of xor are the following:
Try to prove these two properties.
Having these two properties in mind it is clear that if you start your turn with a position $a_1,a_2\dots a_n$ in which the xor is $0$ you won't be able to win this turn (as the xor won't be $0$ at the end, since it will change).
On the other hand, if you start in a position in which the xor is not $0$, you can make it $0$.
So if I start with a position in which the xor is not $0$ I can always make my opponent start his turn in a non-winning position, and eventually win.
If I start in a position in which the xor is $0$ then I will have to leave my opponent with a winning position.