Almost every gun is based on the same simple concept: You apply explosive pressure behind a projectile to launch it down a barrel. The earliest and simplest application of this idea is the cannon.
A cannon is just a metal tube with a closed end and an open end. The closed end has a small fuse hole. To load the cannon, you pour in gunpowder, and then drop in a cannonball. When you ignite gunpowder, it burns rapidly, producing a lot of hot gas in the process. The hot gas applies much greater pressure on the powder side of the cannonball than the air in the atmosphere applies on the other side. This propels the cannonball out of the gun at high speed.