Insomnia can be defined simply as not being able to sleep when one wants to sleep. A medical definition is more complex but involves excluding obvious factors that may prevent sleep from happening. For example, bad sleeping routines, poor sleep environment (too noisy, too hot, uncomfortable bed, troublesome partners, neighbours, etc); or poor sleep habits: lack of regularity, not allowing enough time to sleep; or consuming too much caffeine containing drinks like coffee, etc.
Sleep may be problematic because it being attempted at the wrong time relative to the brain's 24 hour clock (check the clock profiler for this). It can also be because learned sleeplessness (or conditioned insomnia) has developed. The following questions had help identify this.