How the AR-15 Works
When the trigger (orange) is pulled, the front edge of the trigger moves downward, disengaging the hammer (red), allowing the hammer spring to drive the hammer forward into the firing pin. This action causes the firing pin to move slightly forward impacting the primer of the cartridge, thus causing the powder charge to ignite.
The powder ignites causing a rapid build up of pressure inside the cartridge, until it overcomes the press fit of the bullet in the cartridge. This explains why the crimp is so important in cartridges. The lesser the crimp, the lesser the CUP and vice-versa. This action causes the bullet to be expelled from the cartridge and ride down the barrel. As the bullet rides down the barrel, tremendous gas pressure is trapped behind the bullet. Once the bullet passes the gas port, part of this gas pressure is allowed to escape through the gas tube and back to the bolt carrier key. I have seen figures stating that the necessary minimum pressure to activate the mechanism is around 13,000 psi. Since the CUP is around 50,000 psi for this round, in most barrels, there is ample pressure to operate the weapon. With short barrels, the CUP becomes critical and only good quality ammunition should be used, otherwise short cycling is likely.
Since the key (blue) is hollow, the pressure passes through it and into the bolt (red). The gas pressure builds up inside the bolt, causing the bolt carrier (green) to be forced rearward, which in turn unlocks the bolt due to the fact that the bolt cam pin causes the bolt to turn inside the bolt carrier.
As the bolt carrier group is driven rearward, it recocks the hammer for the next round. The bolt also carries the empty shell case with it because the extractor has gripped the rim of the case. The ejector pin inside the bolt pushes forward on the shell case on the left side. This action causes the case to try to move to the right. Once the shell case has moved to the rear far enough that it can clear the ejection port, the case is flung from the rifle.
When all of the rearward momentum has been exhausted, the buffer spring takes over and drives the bolt carrier back forward. As the carrier moves forward, the next cartridge has been forced up to the top of the magazine by the magazine spring, and the lower portion of the bolt catches the cartridge and drives it forward into the chamber. As the bolt is driven forward into the chamber, it is also turned and locked by the action of the bolt cam pin.
During all of the above action, if the trigger has been held, then the disconnector (cyan) has grabbed the secondary sear of the hammer and held it in place. When the trigger is released, the lower portion of the trigger once again grabs the hammer as the hammer moves forward off of the disconnector.
If the trigger had not been held, then the hammer would have been grabbed by the lower portion of the trigger.
In either of the above two cases, the rifle is now ready to fire the next round.