For some, how a gas-operated rifle cycles can be a mystery. But no matter if it's direct impingement or piston driven, the principal is the same. Basically, some of the expanding gas from a fired round is diverted from the barrel and used to thrust the bolt assembly rearward, ejecting the spent cartridge and stripping a fresh round off the magazine into the chamber on the return. Whether that energy goes straight to the bolt assembly or is transmitted to it via a piston all depends on what sort of system you happen to be running. The below animations, while a bit basic, and missing a few parts of the operation, give a pretty solid idea of how direct impingement, short-stroke and long-stroke gas-operations go about their business.