Caffeine is a natural substance extracted from plants, like coffee beans. One cup of coffee contains 27 to 150 milligrams of caffeine, depending on the type of drink, and can keep you awake for about three to five hours. That’s why we recommend drinking coffee at least six to seven hours before bedtime—if you drink caffeine right before bed, it’ll keep you awake when you’re trying to fall asleep.