How do I know when to go to bed?

Bedtime takes time. The answer requires time and testing. It's best to begin with the time you need to wake up. If social or work responsibilities require a specific wake time, even if only a few days a week, start from there. Work back 8 hours, to find optimal bedtime. Follow that schedule for a week or two and see how you feel. Adjust bedtime earlier or later if you're feeling tired or waking up too early.