An airbag is more correctly known as a supplementary restraint system (SRS) or supplementary inflatable restraint (SIR). The word "supplementary" here means that the airbag is designed to help the seatbelts protect you rather than replace them (relying on an airbag to protect you without fastening your seatbelt is extremely dangerous).
The basic idea is that the airbag inflates as soon as the car starts to slow down in an accident and deflates as your head presses against it. That's important: if the bag didn't deflate, your head would just bounce back off it and you'd be no better off.