As you can see, the words can be used almost interchangeably in some cases – but a while needs to be accompanied by a preposition, such as “for” (“I slept for a while”) or “ago” (“I left work a while ago”). Awhile always means “for a while”.
"A while is a noun meaning “a length of time”
“I slept for a while.”
- (compare with “I slept for a bit” and “I slept for three hours”)
“I was away from my desk for a while.”
- (compare with “I was away from my desk for two minutes”)
Awhile is an adverb, meaning “for a time,” or literally, “for a while”.
“I slept awhile before dinner.”
(compare with “I slept deeply before dinner” and “I slept badly before dinner”.)
Logically, this makes sense, with prepositions, "a while" is used, while "awhile" is used as a stand-alone adverb. I am not sure why "a while" looks so wrong to me even when it is used correctly. It is also curious because English lacks analogous pairs like "alot" and "a lot" or "akimbo" and "a kimbo." Usually only one choice applies to most, if not all, situations. Hence, the "awhile"/"a while" dichotomy may strike my eyes as strange, especially since, as the description states, "the words can be used almost interchangeably in some cases."
(Posted by language fan and friend Silas McCracken.)