Wash whites separately from colored clothing every time. Also, if you want your whites to stay bright, wash them separately and use bleach unless labels say otherwise.
Read the label on colored clothes. If it says something like "use cold water," "wash before wear" or "do not use detergents," the garment is probably not colorfast and should be washed separately or tested. If the tag contains no such instructions, chances are the garment is colorfast and safe to wash with other clothes, including whites, if necessary.
Test colored clothes before washing to make sure they're colorfast. Soak the garment in warm water mixed with a couple tablespoons of detergent. After 30 minutes, swish the garment to see if colors bleed into the water. Alternatively, wash colored clothes with a white cotton washcloth or handkerchief and see if it's still white when finished. Or, moisten a white cloth and blot the garment on an inside seam and observe whether the color transfers to the cloth. If the garment doesn't pass the colorfast test, wash it separately.
Wash new clothes separately or with like colors. New clothes are likely to contain extra dye, which can come off in the wash.
Use laundry sheets designed to catch the dyes of colored laundry. Consider them even when washing only colored clothes so dye from one garment doesn't bleed into others. Read manufacturer's directions for product use.