Many medicines can be used as drugs, sometimes even drugs having the potential to be used as medicine.
To me, the difference lies in what you use a certain chemical for. If you use it to get high, you can consider it a drug.
Let me use opiates as an example. Heroin, Morphine, Oxycodone etc, they were all developed as drugs to combat pain. They are some of the best painkillers available because they resemble natural chemicals our bodies produce to feel pleasure. This also means that they produce few side-effects. The problem with opiates is that they can give you too much pleasure causing addiction.
A patient who is in great pain can receive opiates without any problems, addiction developing in very few. However, a person who suffers from very mild pain, or takes opiates to feel good will most likely develop dependence.
There is a very thin line between a drug and a medicine.
Cannabis was considered just another drug for a very long time. Recently, it is being used to combat side effects of chemotherapy.
Ketamine was developed as a tranquilizer and can be used for anaesthesia. It can also be used to hallucinate.
The list of examples is huge, because most chemicals that we can pun into our bodies have more than one effect.
My opinion is that there is great bias when classifying chemicals into drugs or medicines, usually these lists being compiled taking into consideration their theoretical potential for abuse, not necessarily applying for every individual.
If you consider a certain substance as being a drug or a medicine is usually a personal decision, depending on what you intend to use it for.