How long does a cup of coffee keep you awake?

Caffeine stimulates the nervous system. People often consume it to stay alert, but how long do effects last, and how does it impact sleep