So I have this too, try googling 'brain fog'.
I've been trying for years to figure out exactly what causes it. Searching online gives you hundreds of possible causes, for ages I thought it was gluten in my diet, sugar, anxiety causing it, and to some extent I think all of these do affect it.
Recently though I've noticed that sleep might be causing it, specifically breathing through my mouth when I sleep causes me to have a foggy feeling throughout the day, so I'm working on trying to breathe through my nose for the whole night now.
Hope this helps!