It's the most widely used psychoactive substance in the world. Also, one that kids use. It's the most traded good in the world, second only to oil. Yes, most of us consume it daily and we use it to remain awake, more concentrated or just as a social event. Coffee is the most interesting of things. But I asked myself how does coffee, or caffeine to be exact, achieve all of that? Why are we tired and then suddenly awake after drinking a cup of coffee? And that's what you'll find in this article.
Why Do We Feel Sleepy?
To understand the mechanism of action of caffeine, we must first understand why we feel like sleeping in the first place. Two important things are going on.
The first one is our circadian rhythm, which roughly determines when we're supposed to be awake and when we're supposed to sleep. It's controlled by a structure in our brain called the suprachiasmatic nuclei (SCN), situated right above the junction of the optic nerves before they travel towards respective eyes. SCN uses daylight to determine when we're supposed to sleep and be awake.
The second and of particular interest to us is a molecule called adenosine. Adenosine builds up in our bodies throughout the day - the longer we are awake, the more of it is present and the more sleepy we are. It causes what's called "sleep pressure". SCN and adenosine are not connected and act completely separately. So I'll ignore the circadian rhythm and save it for another time.
What Is Caffeine and How Does It Work With Adenosine?
Caffeine is a molecule we find in coffee. It's the substance that's most used and abused in the world. Chemically, it's very similar to adenosine, so it's no surprise that it competes with it for its (adenosine) receptors. The receptors, in turn, cause a specific physiological response that's different when caffeine and when adenosine is bound. Caffeine in general masks adenosine's effect.
After we drink a cup of coffee, 99% of caffeine is absorbed by our bodies in about 45 minutes. It stays there for quite some time - it has a half-life of 5-7 hours. Yes, it takes 5-7 hours for the body to passively excrete caffeine out. However, because of our liver enzymes, the effect wears off a bit quicker and also varies from person to person, based on our genetic predisposition. This is called the elimination half-life.
So, caffeine is bound to adenosine receptors and we're suddenly feeling wide awake. In the meantime, however, adenosine keeps building up as the day progresses. Caffeine thus only tricks our body into thinking that it's not tired, while in reality, it keeps getting more tired. This eventually leads to something that's called a "caffeine crash" that I'm sure regular coffee drinkers have already experienced. When most of the caffeine is metabolised, the receptors are once again free for the adenosine to bind...but this time, its effect is much greater than before we had that cup of coffee. This is why we experience a crash, a sudden urge to sleep. And then maybe need another coffee...
Physiological Effects of Caffeine
But what are the actual physiological effects of caffeine? Some more and some less connected to our sleepiness:
It increases heart rate and coronary blood flow. This is not caused by action on adenosine receptors, but by inhibiting the enzyme phosphodiesterase. Inhibiting phosphodiesterase causes an increase in cAMP molecule concentrations, which stimulates heart contraction. Increasing our heart rate doesn't help us fall asleep. 
In our kidneys, it stimulates urination. This is actually just the opposite of what's supposed to happen in our bodies when we prepare to sleep. Usually, melatonin will decrease kidney function and prevent us from urinating. This also shows implies that melatonin itself doesn't make us fall asleep - it only prepares our bodies for sleep. Our bodies might be feeling asleep, but not our brain because of caffeine. 
Kidneys also release of a hormone called renin as an effect of caffeine. Renin mediates the volume of extra-cellular fluid and arterial vasoconstriction in such a way that increases blood pressure - that means it should cause an increase in extra-cellular fluid and increase arterial vasoconstriction (tightening of the arteries). There are some indications that high-blood pressure also prevents us from sleeping. 
In our brain, it causes the release of hormones such as dopamine, noradrenaline, serotonin, acetylcholine, glutamate and GABA (gamma butyric acid). This is once again achieved through adenosine receptors, which typically inhibit the secretion of these hormones (when adenosine is bound). Higher concentrations of these hormones or neurotransmitters have very diverse effects on our brain and sleep:
- Dopamine is the "feel-good" hormone and is present in low concentrations during sleep - caffeine does just the opposite, it elevates its concentration. We also know that some sleep disorders increase its concentrations, so the cause and effect relationship cannot fully be established when it comes to caffeine. 
- Higher concentrations of noradrenaline again promote wakefulness. It even worsens the quality of REM sleep, the part of the night when we dream and make new connections in our brain. In this case, it's not only wakefulness that's increased, but it also directly decreases the quality of our sleep. 
- Serotonin is an interesting one since it indicates that higher concentrations increase wakefulness, but may also promote REM sleep. This was found in different species of animals and its effects could also be species-specific. Similarly, acetylcholine uses a complex mechanism in the brain to also promote wakefulness and REM sleep. 
- Glutamate is a very important neurotransmitter in our brain. But in terms of sleep, it once again promotes wakefulness and REM sleep, but not NREM (non-REM) sleep.  NREM sleep is especially important for keeping the information we learned during the day "safe". 
- Last but not least, GABAs effects are not clearly defined. GABA itself is an inhibitory neurotransmitter, which means that its function is to stop neuronal conduction. Its effects on sleep and wakefulness are very complex and may in some cases promote wakefulness and in other sleep. 
Seeing that caffeine has very diverse effects on our bodies and brains, we can extract all sorts of information from the data provided in this article. But on thing is for sure: it makes you feel awake and it may fiddle with your sleep.