Sleep affects cognitive function by allowing your brain to rest and recover. During deep sleep stages, your brain consolidates memories, improves problem-solving abilities, and organizes information. Without adequate sleep, your focus, learning, and cognitive function are impaired, making it harder to retain new information.