Difficulty falling asleep or staying asleep is called insomnia.
Three factors affect our ability to sleep. Secondly, our body has an internal clock called the circadian rhythm, which controls sleepiness and wakefulness. It is much easier to enter sleep at certain times of day, especially later in the evening if you work the day-shift. Thirdly, a state of increased mental arousal will prevent sleep. At times this arousal is helpful, for example when a danger is perceived.