During the first 24 to 48 hours, most newborns need to clear mucous out of their stomach and lungs. It's a thick, stringy mucous too. They do a fair amount of gagging that sounds like they are about to throw up. Sometimes they spit the mucous out, and sometimes they swallow it back down. But they need to get it out.
The gagging happens whether your baby is breast fed or bottle fed. It is not because of the milk; it is because of the mucous. Babies born by Caesarian section and early babies seem to have more trouble with gagging, probably because they have more mucous to get out. The gagging should be gone within a day or two.
If you are worried your baby is having trouble getting the mucous out, put one hand over his chest and turn him face down. Give him a few firm whaps on the back with the flat of your other hand. That should be enough. Use the suction bulb in the back of his cheek or just sweep the mucous out of his mouth with your finger.
Thanks to Janelle Aby MD, Stanford School Of Medicine, Newborn Nursery, and Lucille Packard Children's Hospital for the use of occasional photographs.