Spanning Tree Protocol (STP) prevents loops in Ethernet networks by creating a loop-free logical topology. It identifies the shortest path and disables redundant links, ensuring efficient data flow. STP elects a root bridge, calculates path costs, and transitions ports through states like blocking and forwarding to maintain network stability.