Yeah caffeine doesn't stay in the body all that long. If you stop all intake it will basically all be metabolized or eliminated within 24 hours. For most people, the effects diminish earlier than that, usually from 6-12 hours. It's not something that requires a long detox period. If you want to quit and are getting headaches, take an aspirin/tylenol/advil (check that they don't contain caffeine!) and drink plenty of water. I've found the headaches pass after a day or two.
The important rule is that this works for you, but everyone has to discover their own rules.
Most days, I drink 5 to 7 expressos, though there are days I don't drink any coffee, e.g. when not at home. I often drink one (sometimes two) expressos in the hour before going to bed. I'm almost always asleep in a couple of minutes after switching off the lights.
Is a reasonable rule, I'd replace a specific time with $YOUR_TIME which you probably have to experiment to find, seems to differ a lot per person. My time is 18:00, any later and sleep is screwed, 17:45 seems fine.
It can also change throughout your life. I used to be fine if I stuck to 16:00. But now for whatever reason if I drink caffeine after 10:00 it affects my sleep.