Unintentional discharge is the event of a firearm discharging (firing) at a time not intended by the user. An unintended discharge may be produced by an incompatibility between firearm design and usage, such as the phenomenon of cooking off a round in a closed bolt machine gun, a mechanical malfunction as in the case of slamfire in an automatic weapon, user induced due to training issues or negligence, or a simple accident.
An accidental discharge (AD) may occur when the trigger of the firearm is deliberately pulled for a purpose other than shooting—dry-fire practice, demonstration, or function testing—but ammunition is unintentionally left in the chamber. Unintentionally leaving a firearm loaded is more likely to occur when the individual handling the gun is poorly trained, and perhaps also with removable-magazine-fed firearms (as the magazine may be removed, giving an unloaded appearance even when a round remains chambered—see discussion of magazine-safeties below).
A second common cause of negligent discharges is when the gun-handler places their finger on the trigger before they have decided to shoot. With the finger so positioned, many activities may cause the finger to compress the trigger unintentionally. For example, if one attempts to holster the firearm with finger on trigger, the holster edge will drive the finger onto the trigger, and discharge is likely. If one stumbles or struggles (with an adversary) with finger on trigger, the grasping motion of both hands will likely cause the trigger finger to compress the trigger.
Gun safety rules recognize the above possibilities, and aim to prevent them. The primary firearm safety rule usually listed by any source is a version of "Always keep the gun pointed in safe direction." Following this rule ensures that, should an accidental discharge occur, no harm will be done. Second, one's finger should remain outside the trigger guard until the decision has been made to fire the weapon; even if (some would say especially if) one is facing a hostile adversary and has to be prepared to fire at a moment's notice, keeping the finger out of the trigger-guard until one has decided to shoot will prevent an accidental shooting.
When a firearm is not in use, storing it unloaded and in a separate container from ammunition may also help prevent accidental discharges, especially if the stored firearm is "accessed" by an unauthorized user.
On occasion, an accidental discharge can occur by means other than the finger pulling the trigger, such as dropping a loaded weapon. Because of this possibility, most currently produced pistols are designed with a "drop-safety" or firing pin block, a mechanism inhibiting or isolating the firing pin, preventing accidental discharge if the firearm is dropped. However, most long guns do not have drop-safeties.