STP prevents loops by electing a single root bridge and blocking redundant links. It uses BPDUs containing bridge IDs and path costs to elect the root bridge with the lowest bridge ID. The switch with bridge ID 32768.0001.964E.7EBB is elected as the root bridge based on having the lowest bridge ID of the switches shown.