The underlying causes include:

Increased airways resistance (chronic obstructive pulmonary disease, asthma, suffocation)
Reduced breathing effort (drug effects, brain stem lesion, extreme obesity)
A decrease in the area of the lung available for gas exchange (such as in chronic bronchitis)
Neuromuscular problems (Guillain–Barré syndrome, motor neuron disease)
Deformed (kyphoscoliosis), rigid (ankylosing spondylitis), or flail chest. Type 3
Type 3 respiratory failure results from lung atelectasis. Because atelectasis occurs so commonly in the perioperative period, this form is also called  perioperative respiratory failure. After general anesthesia, decreases in functional residual capacity  leads to  collapse  of  dependent lung units. Type 4
Type 4 respiratory failure results from hypoperfusion of respiratory muscles as in patients in shock. Patients in shock often experience respiratory distress due to pulmonary edema (e.g., in cardiogenic shock). Lactic acidosis and anemia can also result in type 4 respiratory failure. However, type 1 and 2 are the most widely accepted. Treatment
Treatment of the underlying cause is required, if possible. The treatment of acute respiratory failure may involve medication such as bronchodilators (for airways disease), antibiotics (for infections), glucocorticoids (for numerous causes), diuretics (for pulmonary oedema), amongst others. Respiratory failure resulting from an overdose of opioids may be treated with the antidote naloxone. In contrast, most benzodiazepine overdose does not benefit from its antidote, flumazenil. Respiratory therapy/respiratory physiotherapy may be beneficial in some cases of respiratory failure.Type 1 respiratory failure may require oxygen therapy to achieve adequate oxygen saturation.
The most common causes are (in no particular order) infections, interstitial lung disease, and pulmonary oedema. Diagnosis
Type 1
Type 1 respiratory failure is defined as a low level of oxygen in the blood (hypoxemia) with either a standard (normocapnia) or low (hypocapnia) level of carbon dioxide (PaCO2) but not an increased level (hypercapnia). It is typically caused by a ventilation/perfusion (V/Q) mismatch; the volume of air flowing in and out of the lungs is not matched with the flow of blood to the lungs. The fundamental defect in type 1 respiratory failure is a failure of oxygenation characterized by:

This type of respiratory failure is caused by conditions that affect oxygenation, such as:

Low ambient oxygen (e.g. at high altitude)
Ventilation-perfusion mismatch (parts of the lung receive oxygen but not enough blood to absorb it, e.g. pulmonary embolism)
Alveolar hypoventilation (decreased minute volume due to reduced respiratory muscle activity, e.g. in acute neuromuscular disease); this form can also cause type 2 respiratory failure if severe. Diffusion problem (oxygen cannot enter the capillaries due to parenchymal disease, e.g. in pneumonia or ARDS)
Shunt (oxygenated blood mixes with non-oxygenated blood from the venous system, e.g. right to left shunt)

Type 2
Hypoxemia (PaO2 <8kPa or normal) with hypercapnia (PaCO2 >6.0kPa). The basic defect in type 2 respiratory failure is characterized by:

Type 2 respiratory failure is caused by inadequate alveolar ventilation; both oxygen and carbon dioxide are affected. Defined as the buildup of carbon dioxide levels (PaCO2) that has been generated by the body but cannot be eliminated.