A spanner works by gripping a fastener and twisting it clockwise or anticlockwise to tighten or loosen it.
The profile of the head (size and shape) fits over, around or into the fastener. When the head is turned, friction (a force that slows down two objects moving past one another) between the profile and the fastener at the contact points causes the spanner to mechanically grip the fastener, providing torque (a turning force) to turn it.
To turn the tool, the shaft needs to be turned on the same plane as the fastener. The user does this by gripping the shaft and pulling or pushing it.
The shaft acts as a lever, magnifying the force input by the user in order to turn the fastener easily.