Pull up on your carpet with a pair of needle-nose pliers. Pull back the carpet from one wall, removing it from the tack strip.
Spray an expanding foam sealer beneath the base board. Be sure to not over-spray, as the expanding foam may spread into unwanted areas.
Allow the foam to expand and dry for a period of time. Refer to the instructions on the can to ensure that the foam cures properly.
Cut back any foam that expands past the baseboard. Ensure that enough room exists to reinstall the carpet properly.
Use a knee kicker to reattach the carpet to the tack strips.
Repeat Steps 3 through 5 to fill in the spaces around the entire room.