Use the electrical box that matches the location, device, and wiring size of your application.
For indoor dry locations, a standard plastic or metal device box is usually fine. Plastic boxes are easy to install and nonconductive; metal boxes are stronger and are required or preferred in some metal-conduit systems.
For outdoor, damp, or wet locations, use a weatherproof box rated for the environment, with a gasketed cover and fittings designed to keep out moisture. “Damp location” and “wet location” ratings are not the same, so choose the correct one.
For heavy fixtures like ceiling fans or large light fixtures, use a box specifically rated to support the weight and motion. A standard light box is often not enough.
For switch and receptacle installations, choose a box large enough for the number of conductors, devices, and splices. If the box is too small, it can violate fill requirements and overheat. Deep boxes are often helpful.
For masonry, brick, or concrete walls, use boxes made for that mounting method, such as old-work, new-work, or masonry boxes.
For fire-rated walls or ceilings, use a box approved for that assembly.
If you’re unsure, match the box to these four things: location, mounting surface, load weight, and box-fill capacity. When in doubt, choose a larger, properly rated box and verify it meets local electrical code requirements.