During sleep, one's brain is shut down. All it can do is to see some dreams from the semi-conscious mind.
Then how does it hear when the alarm clock rings?
The brain does not "shut down" during sleep. While not everything about sleeping is understood, we do know that certain areas in the brain remain active during sleep. There is a good overview on sleep on the website of the National Institute of Neurological Disorders and Stroke.
Until the 1950s, most people thought of sleep as a passive, dormant part of our daily lives. We now know that our brains are very active during sleep. Moreover, sleep affects our daily functioning and our physical and mental health in many ways that we are just beginning to understand
As for hearing, that part of the brain doesn't shut down during sleep - and for good reasons. Sudden, loud noises for example may be a sign of immediate danger. Any animal that just stops hearing a third of the day would be at a huge disadvantage.
The brain even processes the sounds we receive during sleep and doesn't wake on every loud noise. You might find the following article interesting: How do we hear while we sleep?
Using electrodes implanted directly on the human cortex, a Johns Hopkins University undergraduate has located the part of the brain that appears to process sounds while people sleep. This site, in the frontal lobe, may be part of a vigilance system that, for instance, rouses a mother when her baby cries but lets the woman sleep when a truck rumbles by.
Alarm clocks are usually designed to just get louder and louder until we do wake up. Even despite that, some people actually do manage to sleep "through" the sounds, for example of they were very tired and haven't yet had enough sleep. This is speculation, but maybe in that instance the brain prioritizes sleep.
Other articles on the subject are for example Odd Sound Processing in the Sleeping Brain and Auditory information processing during human sleep as revealed by event-related brain potentials, but the main point is that we don't stop processing what happens around us just because we are asleep.