The Food and Drug Administration (FDA) recommendation for safe daily caffeine consumption is around 400mg or 4-5 cups of coffee per day.
However, the effectiveness of caffeine also depends on how fast it is cleared out from the body. Generally, the effects of caffeine on the body lasts anywhere from 4-6 hours.
So, the recommended cut-off time for caffeine use is a minimum of six hours before bedtime.
The rate at which caffeine is cleared out depends on how quickly and efficiently your body metabolizes caffeine. If you are a quick metabolizer, caffeine consumption may not affect your sleep that much. However, if you are a slow metabolizer, the effects of caffeine may interfere with your sleep, and you may need to moderate your caffeine consumption accordingly.
You can learn more about how your genes influence caffeine metabolism here.