Sleep is so closely linked with cognition that physical changes in the sleeping brain can be detected. Researchers from the University of Wisconsin-Madison did just that, using advanced imaging of mouse brains to demonstrate that connections between neurons shrink during the night. The shrinking is at a cellular level (i.e., you don't have to worry about waking up with a tiny shrunken head), and while it may seem like a bad thing, it is actually part of a process of tidying up, breaking connections that are weak to make room for new memories.
The purpose of sleep has been debated in the scientific community for a long time, but this suggests at least one reason for your nightly bout of unconsciousness, and a mechanism by which sleep improves cognitive performance. By trimming back on weak connections, sleep frees up capacity for forming more important connections during your waking hours.
Since the synapses are hypothesized to play a key role in memory, the image above may quite literally be what a piece of a memory looks like, as it's encoded in the brain.