Studies have found "sleeping pills on average only make people fall asleep 12 minutes faster and sleep 11 minutes longer during the night." So why the presumed success? It's a combination of the placebo affect and a minor memory wipe:
Drugs like Ambien have the curious effect of causing what is known as anterograde amnesia. In other words, ingesting the drug essentially makes it temporarily harder for the brain to form new short-term memories. This explains why those who take a pill may toss and turn in the middle of the night but say the next day that they slept soundly. Their brains simply weren’t recording all those fleeting minutes of wakefulness, allowing them to face each morning with a clean slate, unaware of anything that happened over the last six or seven hours.