Power ratchet wrenches, whether they be pneumatic or cordless, work in very much the same way. They typically have a motor that runs at a high RPM and in one direction only, regardless of whether a nut is being tightened or loosened. The output of the motor goes through planetary gearing, which reduces the speed and increases the torque, typically by a gear ratio of between 4:1 and 6:1. The output of the gearing drives a crankshaft with an offset pin on the end of it. This offset pin swings a yoke that is constrained to only move from side to side. With this arrangement, one complete turn of the crankshaft swings the yoke from one side to the other and back again. If you think of a manual ratchet, where you repeatedly swing the handle back and forth – the yoke is doing the same thing, just with a short angular stroke and at a much faster rate.
The inside diameter of the yoke is lined with gear teeth that surround and interact with a pawl-based ratcheting mechanism, much like in a manual ratchet. When the yoke swings from one side to the other, the teeth lock with the pawl to turn the tool output. Then when the yoke swings back, the teeth slip past the pawl without any movement of the tool output. The forward/reverse selector on the tool is used to change the orientation of the pawl so that it either locks with the yoke teeth for clockwise rotation of the tool output or for counter-clockwise rotation.
For some perspective on how fast these different elements are moving, consider one of our power ratchets in which the motor runs at 24,000 RPM unloaded. The motor output goes through planetary gearing that has a gear ratio of 4.75, so that means that the crankshaft rotates at about 5,000 RPM (24,000 RPM divided by 4.75). One rotation of the crankshaft corresponds to one back-and-forth swing of the yoke, so that means that the yoke is swinging 5,000 times per minute. In this particular tool, one swing of the yoke moves the tool output 20 degrees, so that means that the tool output is rotating at approximately 280 RPM (5,000 swings per minute x 20 degrees per swing x 1 revolution per 360 degrees).