+Mahdi Ahnaf Hasan
the gun, in this example, has a firing pin (a straight metal rod similar to a thin nail which functions as an energy transfer device) that when struck on the back end with strong force by either the "hammer" (a spring activated metal actuator that hits the firing pin when released by a pull of the trigger) or a "striker" (a type of internal hammer) is pushed by a strong spring in the longitudinal direction (length wise) the opposite end of the firing pin moves through a small hole in the "bolt" (which is the component that locks the cartridge into place within the firing chamber from the back flat face of the cartridge) area and strikes the primer at the back of the cartridge casing.
When the cartridge primer is struck hard enough by the firing pin, a small chemically reactive explosive charge is set off inside the cartridge casing which in turn sets off the propellant (main explosive powder charge) inside the casing.
The expansion of the resulting explosion of the propellant instantly creates enormous gas pressure inside of cartridge casing, which forces the projectile (bullet) rapidly away from the casing and (hopefully) into the "breach" (the back end opening of the barrel where the projectile and the propellant for the projectile are made ready to fire through the barrel) of the gun barrel.
The explosive gas always takes the path of least expansion resistance as in continues to push the projectile further down the barrel until the projectile has exited the muzzle (the opening at the front end of the barrel) of the gun barrel. The remainder of the exploded gas now has an unrestricted way to expand and eventually dissipate through the now unobstructed barrel and muzzle, into the open air.
The projectile is sent on its way to the target by leveraging the kinetic energy of the explosion plus the mass of the projectile and was guided by the barrel to improve the accuracy of the
trajectory. It is all physics and chemistry.
I hope that this helps your understanding of how the firing "action" of a typical firearm works.
The cycling "action" (making the gun ready to fire again) is well illustrated in the diagram. it