Excluding the 8-9 days they spend as eggs, head lice can live for around 40-45 days on your head. As parasites, they feed on human blood several times a day.
If they are removed from their food source - say from getting knocked out of your hair with a brush or your hand - they can survive 24-48 hours. If they don't find some human hair to crawl back to a new host during that time, they will die.
Even though lice will die after 40-45 days, adult female lice can lay up to 88 eggs during their lifetime. So unless all lice and eggs get killed or removed from your head, they will continue to reproduce and keep you infested long after an individual louse's lifespan (see the lice life cycle).