There are many variations and they all work differently, but in simple terms:
When the trigger is pulled, it releases a hammer.
This in turn flies forward and strikes a firing pin which is thrown forward by momentum.
Once the firing pin travels far enough forward, it hits the primer (little dot on the back) of the bullet. The primer is the part of the gun where mechanical energy is converted to chemical energy.
Once the primer is ignited, it causes a spark inside the cartridge which ignites the gunpowder.
When the gunpowder catches, it rapidly releases its energy in a chemical reaction turning into a gas which rapidly expands and heats up.
As it expands, it needs more room so it pushes on the actual bullet.
When the bullet gets enough pressure behind it, it leaves the casing of the cartridge and begins to travel down the barrel.
As the gases continue to expand behind the bullet and the casing, the bullet picks up speed, always increasing, until it finally exits the barrel.
From here the bullet is traveling as fast as it ever will and begins to slow down as it flies towards its target.