The diaphragm has a primary function of respiration, and a secondary function of seperating the thoracic and abdominal cavity. During contraction, this muscle flattens and draws air into the lungs. During relaxation of the diaphragm, this muscle returns to its resting upward curvature state and pushes air out of the lungs.
The internal intercostal muscles are deeper to the external intercostal muscles, and found between the ribs. They are responsible for changing the volume of the thoracic cavity when the diaphragm contracts and relaxes. Contraction decreases volume of thoracic cavity allowing expiration.
The external intercostal muscles are superficial to the internal intercostal muscles and also found between the ribs. Just like the internal intercostal muscles, they allow the volume in the thoracic cavity to change when needed. Contraction increases volume of thoracic cavity allowing inspiration.