A bit of history
A gun is a ranged weapon typically designed to pneumatically discharge projectiles[1] that are solid (most guns) but can also be liquid (as in water guns/cannons and projected water disruptors) or even charged particles (as in a plasma gun) and may be free-flying (as with bullets and artillery shells) or tethered (as with Taser guns, spearguns and harpoon guns).
The means of projectile propulsion vary according to designs, but are traditionally effected by a high gas pressure contained within a shooting tube (gun barrel), produced either through the rapid combustion of propellants (as with firearms), or by mechanical compression (as with air guns). The high-pressure gas is introduced behind the projectile, accelerating it down the length of the tube, imparting sufficient launch velocity to sustain its further travel towards the target once the propelling gas ceases acting upon it at the end of the tube. Alternatively, acceleration via electromagnetic field generation may be employed, in which case the shooting tube may be substituted by guide rails (as in railguns) or wrapped with magnetic coils (as in coilguns).
The first devices identified as guns appeared in China from around CE 1000. By the 12th century, the technology was spreading through the rest of Asia, and into Europe by the 13th century.
Operating principle
Most guns use compressed gas confined by the barrel to propel the bullet up to high speed, though devices operating in other ways are sometimes called guns. In firearms the high-pressure gas is generated by combustion, usually of gunpowder. This principle is similar to that of internal combustion engines, except that the bullet leaves the barrel, while the piston transfers its motion to other parts and returns down the cylinder. As in an internal combustion engine, the combustion propagates by deflagration rather than by detonation, and the optimal gunpowder, like the optimal motor fuel, is resistant to detonation. This is because much of the energy generated in detonation is in the form of a shock wave, which can propagate from the gas to the solid structure and heat or damage the structure, rather than staying as heat to propel the piston or bullet. The shock wave at such high temperature and pressure is much faster than that of any bullet, and would leave the gun as sound either through the barrel or the bullet itself rather than contributing to the bullet's velocity