It varies depending on which substances you use. Drinking alcohol can cause difficulties in both falling asleep and staying asleep, and withdrawal from alcohol can also cause insomnia. Cocaine and other stimulants (including caffeine) disturb your circadian rhythms, making it harder to fall asleep. Opioids may be sedating at first, but over time they disrupt sleep quality, and insomnia can linger even after you stop taking them. Cannabis use is associated with less time spent in REM sleep. All of these substances affect brain chemistry and impact your sleep patterns.