Summary: Waking time is more important than sleeping time. You need a stress-free lifestyle with fixed routines that you follow with discipline, to fix any disruption in your sleep cycle. Eat on time. Exercise
Some research I've done on this subject that may help you:
Why do we sleep?
Our body needs sleep to rest, recuperate and do general maintenance internally on many of our organs. A good sleep thus reduces the wear and tear of our organs and makes us healthier, as our body gets some time to replace the damaged or dead cells. Another very important function is to allow the brain some much needed rest, by "hibernating" parts of it. This helps in regulating emotions (allowing you have to better control over your emotions) and also with improving memory. The brain consumes a lot of energy and thus also produces a lot of waste - so "cleaning" of the brain is also an essential function. Apparently brain cells shrink when you sleep, thus creating gaps in the brain tissues that allow more fluids to enter it and clean the waste by-product away (studies show that patients with Parkinsons and Alzheimer have brains with more "waste" than the average healthy individual).
So if you don't get a good sleep, you will feel tired, lethargic, less alert and more emotional. If this persists in the long-term (months / years), you will actually cause physical damage to your body at the cellular level, which can progress into your organs not functioning optimally.
Why can't we sleep?
Physical health issues can cause us to have a restless sleep (@schwartzworld has described some of them - https://news.ycombinator.com/item?id=33315140 ). Mental health issues too can cause us to lose sleep or oversleep - this can be something as common as stress, depression or anxiety, or something more serious like addiction or personality disorders - all of which can degenerate into unhealthy lifestyles causing sleeping disorders. A sedentary lifestyle with few physical activities also results in poor sleep. The weather too can interfere and disrupt your sleep.
Is sleeping too much also unhealthy?
Yes. Prolonged oversleeping can cause many disease like diabetes, obesity, heart issues, depression etc.
How can I improve my sleep hygiene?
If you don't feel rested or your sleep cycle is disrupted for some reason, first consult a doctor and rule out any physical and mental health issues. (Tip for mental health issues: if you are suffering from stress, mild depression or anxiety, I highly recommend the book "Feeling Good: The New Mood Therapy" by Dr. David D Burns, to learn some self-help cognitive therapy). If you have a mildly dysfunctional lifestyle, start by creating and following a fixed routine (with set waking and sleeping time) with lot of activities in the day. Make sure the activities don't spill over to your sleep time. Ensure that exercising daily - even something as just 10-15 minutes of walking the neighbourhood or to a store - is part of your daily activities. If you are not able to fix and follow a routine, consider getting professional help from a therapist.)
If you don't have physical and mental health issues, figure out how much sleep you need to feel well-rested (this will vary between individuals, but is usually between 6 to 8 hours for most adults. Seniors (60+) tend to need less sleep as they age - an indian President mentioned in one of his book that he only slept 3-4 hours by the time he was 80+). Based on how much sleep you need, fix a time to wake up (anywhere between 5:00 AM to 8:00 AM) and sleep (anytime after sunset or after 9 PM).
An important thing to remember here is - If you want to sleep early, you have to wake up early. So don't waste your energy focusing on when you sleep, but rather focus on when you get up.
So to begin with, force yourself to wake-up every day in the morning at the fixed time. To help with this, ensure that you sleep near a window with natural sunlight (if that is not possible, then try to get a smart light, with yellow colour light, that is programmed to switch on every morning at sun rise - sleep under the light so that the light shines on your face). Use an alarm clock (preferably which plays some music so that you don't wake up irritated) and keep it far away from you, so that you have to get out of bed to stop it.
To ensure that you can sleep on time, you need to develop good eating habits and eat right on time. Our body is incredibly flexible and adaptable when we are young. If you have ruined your sleep cycle, you also consume food at odd times. Consuming food is one of the important triggers that activate many bodily functions. So fixing when you eat food, eating on a regular schedule, also helps the body reduce stress and resets your body's clocks and cycle. If you have a dysfunctional sleep cycle, and you consume food when you are feeling sleepy (whatever odd time it is), your body adapts and assumes that you will be going for another late night bender and will automatically disrupt your sleep. Similarly, if you don't eat properly also (like skipping one or two meals), your body can disrupt your sleep. So try to make sure you have 3 heavy meals (breakfast, lunch, dinner) and 2 or 3 light meals (like tea, coffee or snack in between the major meals) on time, regularly. Ensure that dinner is always one or 2 hours before your sleep time, so that the body has time to digest the food before you sleep.
Avoid stimulating activities before bed time. Avoid stimulations, like phones, computers, books in bed, around your bedtime.
Environment - your body temperature naturally falls when you sleep. This can be used to trigger sleep too. If the temperature is not comfortable, you will not be able to fall asleep or sleep comfortably.