Muscles of respiration
The various muscles of respiration aid in both inspiration and expiration, which require changes in the pressure within the thoracic cavity. The respiratory muscles work to achieve this by changing the dimensions of the thoracic cavity.

# Principal and Accessory Muscles of Inspiration
There are two main groups of inspiratory muscles: principal and accessory. Principal muscles are used regardless of the level of breathing required, while accessory muscles are only used during forced breathing. For example, during heavy exercise and because of some respiratory conditions such as Asthma.
The principal muscles are the external intercostal, the intercondral part of the internal intercostal muscles, and the diaphragm. Both the external intercostal muscles and the intercondral elevate the ribs, thus increasing the width of the thoracic cavity, while the diaphragm contracts to increase the vertical dimensions of the thoracic cavity, and also aids in the elevation of the lower ribs.
The accessory muscles of inspiration are: The sternocleidomastoid (elevated sternum) and the scalene muscles (anterior, middle and posterior scalene). After heavy exercise, people will often lay down with their hands fixed. This has a similar effect to fixing the insertion of the accessory muscles, and thus when the muscles contract, the origin (the upper ribs and/or the sternum) is pulled to aid respiration

# Muscles of Expiration
During quiet breathing, there is little to no muscle contraction/relaxation involved. This process is simply done by the elastic recoil of the lungs and the rib cage.
During active breathing, the internal intercostals, with the exception of the intercondral, and the abdominal muscles (rectus abdominis, external, internal oblique and transversus abdominis) pull the thoracic cage in and force air out of the lungs.

# The intercostal muscles
Along with the diaphragm, the intercostal muscles are one of the most important groups of respiratory muscles. These muscles are attached between each rib and are important in manipulating the width of the thoracic cage. There are three layers of intercostal muscles.
The external intercostal have fibres that go forward and downward. These fibres are called the antero-inferior, and are sometimes referred to as the front pocket muscle since the fibres mimic the direction a hand would enter a front pocket. The antero-inferior fibres have the effect of lifting up the ribs during contraction. Anteriorly, the external intercostal muscles do not directly attach to the sternum, but are replaced by the anterior intercostal membrane.
The internal intercostal also have fibres, which go backward and upward. These are called the postero-superior, or the back pocket muscles. The last layer is the innermost intercostals and consists of three separate parts; the subcostal (posteriorly), the innermost intercostal (laterally, which often causes confusion with the innermost intercostal referring to all twenty groups) and the transversus thoracis (anteriorly). The innermost intercostal muscles are also "back pocket" muscles. The internal and innermost intercostals have the opposite effect of the external intercostals and aid in forced expiration. The internal intercostal is replaced by the posterior intercostal membrane posteriorly.