CPAP is primarily used to treat obstructive sleep apnea, a condition where the airway collapses or becomes blocked during sleep, causing pauses in breathing and disruptive snoring.