The lungs function in the respiratory system is to extract oxygen from the atmosphere and transfer it into the bloodstream.