Registers
Inside the Uno's ATmega328P, PORTB is a register: one byte at data address 0x25. Unlike RAM, each bit is wired to a pin: bit 0 drives pin 8, bit 5 drives pin 13. Now PORTB holds 0x01, so only pin 8's LED glows.
In C, PORTB is a macro (a name swapped for code) for *(volatile uint8_t *)0x25: the byte at address 0x25. Reading it reads the register; writing it changes the pins. volatile makes the compiler do every read and write for real.
Masks
Line 1 builds a mask: a byte with a 1 only in the bits you want to touch. 1 << 5 shifts a 1 five places left, giving 0b00100000, which is 0x20. Bit 5 is pin 13.
PORTB |= m reads PORTB, ORs it with the mask and writes the result back. x OR 0 keeps x; x OR 1 gives 1. Only bit 5 changes: 0x01 becomes 0x21. Pin 13 lights, pin 8 stays on.
~m flips every bit of the mask: 0b11011111. PORTB &= ~m ANDs with it. x AND 1 keeps x; x AND 0 gives 0. Bit 5 clears, 0x21 becomes 0x01: pin 13 goes dark, pin 8 stays lit.
PORTB ^= m flips bit 5. x XOR 0 keeps x; x XOR 1 flips it. 0x01 becomes 0x21 and pin 13 lights. Run the same line again and it goes dark: a blink in one line.
PORTB & m keeps only bit 5 and writes nothing back. The result is 0x20, not zero, so on is true. Had bit 5 been 0, the result would be 0, so false. To read input pins, you read PINB instead.
Pitfalls and the library
A plain write puts all eight mask bits into PORTB at once. Bit 5 stays 1, but bit 0 becomes 0 too, so pin 8's LED goes out by accident. |=, &= and ^= change only the bits you mean.
digitalWrite(13, LOW) looks up port B and mask 0x20 in tables, checks for PWM (pin 13 has none), pauses interrupts (events that jump in mid-code), then runs *out &= ~bit: the same AND NOT. 0x20 becomes 0x00.
What happens
;; step 1/9 · addr PORTB I/O 0x05 + 0x20 = data address 0x25 bits b7 b6 b5 b4 b3 b2 b1 b0 now 0 0 0 0 0 0 0 1 = 0x01 b0 pin 8 (PB0) LED on b5 pin 13 (PB5) LED off
Before line 1 the sketch has already made pins 8 and 13 outputs (DDRB = 0x21, with pinMode) and set pin 8 HIGH. Each LED in the figure stands for an LED and its series resistor; the lesson "Digital output: driving an LED" sizes that resistor. A read-modify-write takes several steps. If an interrupt changed PORTB between the read and the write, its change would be lost. That is why digitalWrite saves the status register SREG, turns interrupts off with cli(), and restores SREG afterwards.