The actual answer is to set your wake up time, and go to bed when you're sleepy, whenever that is.
Just get up at the same time each day (no snooze alarm, get out of bed, else you might be less sleepy at the end of the day) and you're half-way there.
Figuring out how long you actually need to sleep is a process involving changing how long you try to sleep for. (So if you set your wakeup time at 7AM, maybe try 11PM) Taking note of how long it takes to get to sleep and if you wake up during the night. (Not sleepy, taking too long at 11PM, then go to bed at 11:30PM for multiple nights and see if you're sleeping through more. Sleeping quickly and through the night, but still feeling tired after many nights on average, maybe try a bit more sleep instead)
Never try to go to bed early when you're not sleepy, it won't work.
Also accept that your sleep quality is going to vary from night to night, that's life.
As recommended by a sleep psychologist (not me).