There are different laws on obtaining and using Modafinil, depending on where you live. In Mexico, for instance, no prescription is necessary. On the other hand, almost any use of Modafinil in Russia and China, even with a prescription, is illegal.
In the United Kingdom and many other countries, it can be obtained legally with a prescription for conditions such as narcolepsy. It is not prescribed for cognitive enhancement use.
In 2016, there have been some drastic changes to the British laws regarding Modafinil and other nootropic drugs. The new Psychoactive Substances Act has outlawed the production, supply, import, export and possibly even possession of any drug which “by stimulating or depressing the person’s central nervous system, [affects] the person’s mental functioning or emotional state.” However, since Modafinil is also classified as a “medicinal product”, it is still legal to import it.
Under the new law it is still not legal to be using Modafinil without a prescription, and the penalties go as high as one year in prison for a first-time offense. So, it is a good idea to not carry it around on your person. This makes the use of a discreet and reliable source even more necessary in the United Kingdom today.