Awhile is an adverb meaning "for a while."
A while is a noun phrase meaning "a period of time."
The major difference is in function. Awhile acts like an adverb, describing an action. For example:
I talked awhile.
We drove awhile.
A while, on the other hand, acts like a noun. For example:
It has been a while since we've spoken.
A while can pass in the blink of an eye.
Note
These expressions are often interchangeable. For example:
I ran for a while.
I ran awhile.
In such cases, which expression should you use? Sentence rhythm should guide your choice, though using awhile is a small step toward concise writing.