There are numerous causes of insomnia, some more obvious than others. Many can be remedied yourself as they are linked to sleep environment and lifestyle factors that are important to your well-being.
Sleep is not an ‘all or nothing’ phenomena. Parts of your brain can be asleep while others are awake. If a particular part of the brain wakes up, it is possible to carry out the behaviour for which that part of the brain is responsible like walking or talking, without being conscious of it. The conscious part of the brain is still asleep.