Ever wonder why air fresheners don't always take away the bad smells in your home or office? Well, air fresheners just releases a different odor; they don't absorb the bad stench. A surprising substance that can absorb smelly odors is coffee grounds.
Things like coffee grounds and charcoal are called "physical deodorizers," because they absorb tiny particles in the air that are causing the smell. The problem is, eventually they reach a state called "equilibrium," in which the deodorizer has absorbed all it can. Then it actually starts releasing the bad smell itself--along with the smell of old coffee grounds.
Luckily, baking soda actually clears up bad smells, and not because it puts out its own perfume, or because it absorbs particles. Instead, it chemically neutralizes the odor. Baking soda is "basic," meaning the opposite of "acidic." Most bad smells strike us that way because they are strongly acidic. A good example is sour milk.
Much like sour milk, garlic and onions are also acidic. Actually, baking soda is pretty unique in that it can also neutralize odors that are too basic, like dead fish. The closer to chemically neutral something becomes--not too basic, not too acidic--the less bad it smells to us.