The respiratory system is responsible for taking in oxygen and letting out carbon dioxide. The most important parts of the respiratory system are the nose, windpipe (trachea), lungs. When we breathe, we take in air through the mouth and nose flowing through the trachea and entering the lungs.
Just below the lungs, there is a large muscle between the chest and abdomen called diaphragm. The diaphragm also aids the airflow by moving up and down during inhalation and exhalation. There are phrenic nerves that start from the neck and reach the diaphragm. These nerves take control of the movement of diaphragm. If these nerves, for some reason do not function properly, it results in sudden contraction of the diaphragm muscles. This contraction causes hiccups. The sudden spasm (contraction) of the diaphragm makes the vocal cord close suddenly. This results in a rush of air into the lungs. The body reacts to this with the sound we call hiccups.
The reason that could irritate the phrenic nerves could be over eating, eating too much spicy food, drinking too much alcohol or drinking a very hot/very cold beverage and so on.
Hiccups generally stop within a few minutes to a few hours. Hiccups that last longer than 48 hours are called persistent hiccups. Hiccups that last longer than a month are called intractable hiccups. Though very rare, hiccups that last very long may be a sign of a more serious health problem.