A gun is a tool for making a bit of metal move very fast. It accomplishes this goal by accelerating the bit of metal over time. First, the gun seals the bit of metal in an area where it only has one direction to go, and then creates pressure behind the metal, pushing the bullet forward.
The brass casing of the cartridge helps create a pressure-tight seal. The steel parts of the gun can hold up to the pressure, but it is difficult to make steel parts mesh perfectly enough that pressure can’t leak. The brass expands under pressure, pushing up against the mostly-closed chamber and forming an air-tight seal. Also, when the gun has finished firing the bullet, that casing is ejected, removing a lot of waste heat and preventing the gun from overheating.
The pressure is created by setting things on fire, with a combustion reaction. The combustion reaction produces hot gas, which creates the pressure required to accelerate the bullet down the barrel.
In black powder firearms, there was a separate fuel and oxidizer. The fuels used were sulfur and charcoal, and the oxidizer was potassium nitrate. When heated, the fuel and oxidizer would combust, creating more heat and pressure, and this would push the bullet down the barrel.
This doesn’t work for modern firearms, because we want to be able to just pull a trigger, not have to apply heat to the bullet. So, in modern firearms, you have a two-step process, with a primer and smokeless powder.
The primer has to explode under friction. The primer’s job is to be struck by a piece of metal when the trigger is pulled, and explode, creating the heat needed to set off the gunpowder. The chemicals used for this are lead styphenate, barium nitrate, and antimony sulfide. Powdered glass is often added to help with detonation. This mixture detonates when struck. Typically, there are two pieces of metal with the primer compound smeared between them. When the trigger is pulled, and one piece of metal smashes into the other one, creating the friction and pressure needed to detonate the primer.
Once the primer goes off, the gunpowder is hot enough to start its own combustion reaction. Modern guns use smokeless powder, which is primarily made of nitrocellulose. Nitrocellulose is highly combustible, and once heated, will produce lots of heat as it decomposes into smaller elements: CO2, N2, and H2O.