Keep your carpet rolled up, preferably in a cool dry place. Avoid basements and attics, as these areas generally attract pests. As carpets are made from natural materials and contain no toxins, there is an increased risk of pests. Avoid exposing the carpets to direct sunlight too, as this can fade them.
Gently roll up the carpet, pile inwards, ideally onto a cardboard tube to avoid any creasing. Lay a few mothballs for extra protection against pests. Then tie a couple of straps around the carpet so that it doesn't unroll. Pack the carpet well, ideally in a couple of large plastic bags and seal the ends well with tape. Unroll the carpet at least every three months to vacuum it. You should also check the carpet thoroughly for pests that have crawled into the pile. Lay a few more mothballs, as their effect diminishes over time.
Under no circumstances should the carpet be wet or damp when you roll it up for storage. Nor should the carpet be stored in an upright position, as this could result in it losing its shape. If you must store your carpet in a basement, avoid laying it directly onto a concrete floor that could be damp, lay it on some boards to keep it off the concrete.
Note: a carpet that is laid on the floor will not be attacked by pests.