Firearm maintenance
Firearm maintenance (or gun care for short) is a series of routine preventive maintenance procedures aiming to ensure the proper function of a firearm, often with the use of a variety of specialized tools and chemical solutions. Typically such maintenance is performed by the firearm owner using either simple methods such as cleaning the firearm with oil or other cleaning solutions or more sophisticated practices such as lubricating moving parts with oil/grease and recoating exposed surfaces with protective finishes such as varnishing or bluing. When a firearm is presented with physical damage related to the ordinary use of the firearm, or when a firearm malfunctions in a life-threatening manner, a professional gunsmith should perform advanced maintenance to determine if the firearm is repairable and or safe to shoot anymore. Necessity 

An inadequately maintained firearm will often accumulate excessive fouling and dirt within the barrel and receiver, which not only can clog up the rifling and decrease the firearm's accuracy and precision, but can also interfere with the proper operation of the action and lead to potentially dangerous malfunctions. Furthermore, some of the fouling and dirts are either corrosive themselves, or capable of making the firearm vulnerable to rusting and wears, and thus can lead to irreversible damages to the firearm over time. The consequences of neglecting proper maintenance can be serious. For instance, during the Vietnam War, the newly issued M16A1 assault rifle was distributed to US troops with marketing literature from Colt Firearms claiming that the weapon was self-cleaning, which implied to many to mean that it did not have to be routinely maintained. However, this misapprehension compounded the rifle's design flaws and made the weapon notorious for repeated failures in combat, which led to needless casualties among US forces. Once the problem was acknowledged by the US military, the weapon was not only subject to upgrades, but US troops were also trained in proper maintenance of the weapon and supplied with cleaning kits  and an illustrated booklet on the subject by Will Eisner. With these measures, the reliability of the M-16 improved considerably. Cleaning 
The ordinary firing action releases fine particles of gunpowder, metals (mostly lead and copper from the bullet moving over the riflings) and other contaminates into the inner spaces of a firearm, which may cause malfunctions or in rarer cases of extreme buildup may raise the barrel pressure too high causing the firearm to explode (catastrophic failure) upon being fired. It has been widely reported that firearms without a spring to control the inertia of the firing pin require constant cleaning of the bolt assembly, as extremely dangerous phenomena such as slamfire may occur. Slamfire is a malfunction in which a firearm which is normally semi-automatic may temporarily and involuntarily become fully automatic, firing repeatedly — without another pull of the trigger — until the firearm is out of ammunition or jams. Every major firearms manufacturer provides detailed information on the proper methods used to disassemble, clean and then reassemble a firearm they produced. This information is usually packaged with the firearm. In the event that this information is not present with the firearm at the point of purchase, it is advisable to ask the manufacturer where this information may be obtained. For safety reasons the manufacturer's directions for cleaning, maintenance and care should always be followed. There are many different types of weapon and firearm cleaning kits available on for sale. These kits will give you the necessary tools and materials to properly clean your firearm safely and effectively. These kits help keep your firearm stay maintained and properly lubricated, making the firearm last longer without failure. However, pre-made cleaning kits often do not contain everything a specialty gun owner may want or need. This is why many gun owners build their own custom cleaning kits which include extra materials or specialized parts to best keep their weapon in proper order. Lubrication 
Firearms produce massive momentary forces upon firing a bullet. A typical 9mm projectile produces a maximum of  of pressure in the instant of firing. The amount of pressure a firearm may endure for the first few milliseconds after the cartridge fires can be over 2,300 times more than the normal atmospheric pressure. Therefore, it is important for the safety of the shooter, and the longevity of a firearm that it is properly lubricated as per the manufacturer's specifications. When in an extreme and life-threatening situation such as preparing for combat, the manufacturer's recommended lubricants may not be available to soldiers, or others who may enter these scenarios. If there is time to perform firearm maintenance before a life-threatening emergency (such as daily cleaning of a rifle in a combat zone) it may become necessary to use other sources of lubrication, as a firearm will function better with some lubricant than it will with none. One United States Marine Corps sergeant recounts that synthetic motor oil performed better than standard military issued lubricant in extreme conditions. However it is advisable to immediately return to the standard recommendation of the firearm manufacturer when conditions allow. Gun owners need to keep in mind that not all gun oils are made for the same thing. Some are specifically used for lubrication, while others are for cleaning. Greases may also be used in heavy duty situations where oils are not sufficient. Safety 
It is critically important that a firearm is free of ammunition before beginning maintenance. The National Rifle Association of America teaches gun owners that "before cleaning your gun, make absolutely sure that it is unloaded. The gun's action should be open during the cleaning process. Also, be sure that no ammunition is present in the cleaning area". When reassembling a firearm after it has been cleaned, it is very important to know how to put the weapon back together properly. Failure to reassemble your firearm properly could lead to malfunction when firing and could lead to injury. See also 
 Gunsmith
 Cleaning rod
 Handloading

References