The funny thing about my obstructive sleep apnea is I didn't think I was having trouble sleeping. I'd sleep 8 hours and have no memory of any problems. In reality I was gasping for breath every 50 seconds, all night.
Note I had no symptoms during the day (even when jogging or weightlifting). In my case it's induced by dust mites and there is no good defense against this except asthma medication.
There are also people with sleeping problems due to silent reflux.
If you feel you're clearing your throat often, burp a lot or lacking air, check for those two.
I used to think (or I believe was told), that two cups and no more before noon is ok, but found my sleep was just an utter mess. I tried everything , sleep test, black out curtains, magnesium, CBD oil, melatonin, yet it never occurred to me it could be coffee as I never drank it outside of the morning.
I cut out caffeine completely. Had a horrible withdrawal; headache from hell, back ache , neck ache, everything ache, but then around day 6 or 7 I did something I had not done in years - slept all night AND had a vivid dream (showing I was in deep REM sleep).
Poor sleep can also be caused by stress/anxiety/depression, or just poor sleep hygiene.