Sleep apnea causes daytime sleepiness, snoring, trouble staying asleep, and restless legs. A sleep study involves spending two nights in a sleep lab where sensors monitor breathing and sleep patterns to diagnose obstructive or central apnea. If apnea is diagnosed, a second study determines the optimal pressure for a CPAP machine, which is then prescribed.