A ratchet is a handle that snaps into one end of a socket by means of a square-drive connector.
The other end of the socket fits over a fastener.
A mechanism in the ratchet allows the handle to engage and tighten the fastener when you swing it in a clockwise direction and turn freely when you swing it counterclockwise.
A switch on the ratchet reverses the action to loosen the fastener.