It all starts with mucus
Boogers begin their lives as nothing more than mucus. While the word "mucus" may inspire revulsion, it's a normal (as well as vital) part of your biology. You might have heard of mucous membranes, which can be found along the gastrointestinal tract (eating and pooping), the reproductive tract (sexing and reproducing), and the respiratory tract (breathing).
For now, let's focus on the mucus that eventually winds its way down to the end of your nostrils. It starts in your sinuses -- you know, those hollow cavities in your skull -- and even though you're usually only aware of your sinuses when they flare up and become a symbol of hell on earth, they're actually working hard every day to maintain good health.
It turns out that sinuses aren't totally hollow after all; they're lined with a pinkish membrane that manages to produce mucus all day and all night. In fact, your respiratory tract produces about a quart of slime each day. Most of it disappears without a second thought down your throat (yum!), while some glides down through your nose. This mucus is mostly water, though it's also loaded with glycoproteins and enzymes that attack germs.
Obviously you use your nose to breathe, and this is where mucus dons its germ-fighting costume. Breathing invariably means you're sucking up garbage that you definitely don't want in your body, including viruses, bacteria, and fungus -- not to mention dust, dirt, pollen, and other tiny foreign particles.
Fortunately, mucus plays an important role in fighting the filth. In the nose, it acts as a filter that traps smaller particles. These particles are either eventually swallowed, meaning your digestive system makes short work of them, or they're forced out via a cough or a sneeze.