Most cacti grow in arid regions with very poor, rocky soil. They can absorb nutrients in some of the worst conditions. Potted cacti make great houseplants, but eventually they will outgrow their pots and need to be replanted in fresh cactus soil. There are a variety of soil choices available that can be purchased commercially; alternately, you can make your own mix quite easily.
Cacti are succulents, and each plant has a preference for the type of cactus soil in which it performs best. You can simulate this at home fairly easily with ingredients from your local nursery or plant dealer. Spineless succulents prefer cactus soil with a bit more organic matter. They will also rot if over-watered, so the drainage is still very important to them. Potting mixes may not be ideal since they typically contain peat, which retains moisture and compacts fairly easily.
If you'd like to make your own soil you can try coir, which is made from shredded coconut husks, instead of peat as it can absorb water easily and doesn't compact. A typical recipe for homemade cactus soil is two parts compost, two parts sand and one part gravel. Nurseries and garden centers carry clean often used in a sandbox; this sand has been washed and sometimes sterilized, so it won't contaminate your plant. If you have a lot of cacti of differing species, you can keep ingredients on hand and tailor your homemade mix to each plant.
To re-pot your cactus, you'll need your favorite cactus soil mix and the smallest pot available for the plant. There should be a little room between the cactus and the sides, but not too much. A larger pot will hold too much water and can make the cactus rot. Put a large amount of drainage material such as gravel or pieces of a broken clay pot in the bottom.
Make a holder from folded newspaper to shield your hands from the cactus spines. Heavy leather gloves may help to protect you against the large stickers, and shield you from clingy, scratchy small ones. Wrap the newspaper holder around the plant and use it to gently remove it from the pot, along with the cactus soil. You should make a new holder for each plant to avoid spreading any pests or diseases.
Once you have removed your cactus, you can gently prune the roots if necessary before replanting. Cacti and succulents prefer a smaller container with only a little room around the rim. You can put gravel or ornamental stones on the soil to dress it up a bit. To simulate its desert habitat, water it once a week during the summer growing season, letting it dry out completely between drinks. If you've chosen the best cactus soil for your plant, it will be quite content until it outgrows its pot again.