I would shut it off an hour before you go to bed or two hours before you go to bed. Depending on what you feel comfortable with.
I would think about half an hour to an hour – giving yourself enough time to complete tasks that dont involve a device before sleeping. Showering, reading a book, setting everything up for tomorrow, ect!
I've heard that an hour between sleep and phone time should be your norm. Most phones these days come with a blue light filter these days. Turning this on means the screen is less harsh on your eyes you could try this if you find your not getting off your device soon enough.