The caffeine cut-off, worked out
The rule is simple once you have two numbers from NIOSH: about 30 minutes to act, five to six hours for half of it to clear. Work backwards from the time you plan to be asleep. If the shift ends at 7 am and you are in bed by 8, a coffee at 5 am is still about half there at 10 or 11 am, in the middle of your sleep. A coffee at 2 am is down to about a quarter by 1 pm. So the last caffeine is at the 1 to 3 am break, and the 5 to 7 am stretch is caffeine-free however flat it feels. Two drinks a shift, start and break, keeps most people under the FDA's 400 milligrams; a third large energy drink can take you over it on its own. If you have a cup at 7 pm, 1 am and 5 am and then sleep badly all week, the caffeine is a likely reason, and NIOSH says so.
Days off: do not flip all the way back
The temptation after the last night is to stay up all day and "reset". NIOSH calls switching schedules more than once a week a perpetual state of jet lag and warns that staying awake all day after the last night raises short-term accident risk. Its compromise: on work nights, sleep as soon as you get home and as long as you can; on days off, stay up until about 3 or 4 am and sleep until noon or 1 pm. That keeps one block, roughly 8 am to noon, as sleep in every 24 hours, so your body is not asked to move the whole clock twice a week. If you rotate between day and night shifts and cannot adjust, NIOSH's advice is to see a sleep specialist rather than keep guessing.