The hammer is a part of a firearm that is used to strike the percussion cap/primer, or a separate firing pin, to ignite the propellant and fire the projectile. It is so called due to the fact that it resembles a hammer in both form and function. The hammer itself is a metal piece that forcefully rotates about a pivot point.
Firearms, initially known as “hand cannons”, first became a viable weapon in 1364  through the advancement of chemical technologies to create a gunpowder efficient enough to launch a projectile at high velocities in a hand-held weapon. The issue quickly arose of how to effectively ignite the gunpowder while maintaining the weapon’s aim at the target. Initially, the problem was solved by using a “slow match”: a chemically treated piece of rope that would stay lit for an extended period of time. The smoldering end of the rope would then be manually brought into contact with the gunpowder through a touch hole in the barrel of the weapon when the user was ready to shoot. It proved difficult for the shooter to both keep the weapon aimed and level as well as ignite the gunpowder with the slow match.
The first step to a true hammer system arose shortly after the introduction of the slow match: the matchlock system, introduced in the early 1400s. It acted as an arm, known as a serpentine, that held the lit slow match. When the trigger was pulled, the arm would swing forward from its cocked state (similar to a hammer) via potential energy stored in a spring and bring the lit slow match into contact with the gunpowder. The weapon could be utilized with increased accuracy, since the shooter could maintain both hands on the weapon.
By 1509, the wheellock system arose to solve some difficulties of the matchlock system, though it was a very expensive system. The wheellock system used a piece of pyrite attached to an arm called a dogshead that would be brought into contact with a metal wheel that rotated when the trigger was pulled. This would, in turn, shower sparks upon the gunpowder and cause the weapon to discharge. The wheellock represented a major advancement, for it removed the need for maintaining a continually lit slow match which could go out or give off the shooter’s location in a time of need.
Following the introduction of the matchlock, the flintlock was introduced in the mid-1600s. The flintlock is similar to the wheellock system, but instead of the hammer mechanism holding pyrite and coming into contact with a moving wheel, the arm (called a cock) held a piece of flint and would be brought forcefully into contact with a steel plate when the trigger was pulled. This would also cause pieces of steel to flake off and ignite due to the friction thereby igniting the gunpowder. This method was also far less expensive that the wheellock system.
In 1822, the flintlock system was replaced with what can be called the first hammer system. This arose after Scottish clergyman Reverend Alexander Forsyth discovered the property of mercury fulminate (Hg(ONC)2) to combust when struck. Using this discovery, the percussion cap was created. The cap was a small metal cup filled with volatile chemicals placed at the rear of the barrel over a nipple in what was known as the caplock mechanism. A true hammer was cocked via a spring system and held in place until the trigger was pulled to release the hammer. The hammer would then swing forward and strike the percussion cap which would in turn ignite and cause the gunpowder to ignite and fire the weapon.
The percussion cap was in wide use for almost five decades until the wide-spread introduction of the self-contained cartridge which contained the projectile, gunpowder, and percussion cap all in a single shell that could be easily loaded. The introduction of such a technology led to the implementation of the firing pin and hammer system that is now used in certain weapons. This was done to transfer energy from the still required hammer to the primer within the self-contained cartridge in order to discharge the weapon.
There are some notable drawbacks to the external hammer system compared to other modern, internal designs. In single-action revolvers, specifically, there is an ever-present danger of accidentally discharging the weapon if the hammer is struck with a shell loaded in the chamber. There is nothing to prevent the hammer from contacting the firing pin and by default the cartridge, in some models, and so the gun will be discharged unintentionally.
Other models do have an internal safety mechanism that prevents contact between the hammer and the firing pin unless the trigger is actually pulled. Even so, many single-action revolver owners choose to carry their revolver with the hammer resting on an empty chamber to minimize the risk of accidental discharge. Additionally, for those who carry their firearm as a personal defense weapon, there is the ever-present worry that an external hammer may catch on a loose article of clothing in an emergency situation, because the hammer protrudes at an angle from the rear of the weapon, and as the owner moves to quickly draw their weapon, the hammer may snag on clothing and cause the loss of seconds in a dangerous situation. Paul B. Weston, an authority on police weapons, called the external a “fish hook” that tended to snag clothing during a fast draw.