How to Replace the P-Trap on a Sink

A drain trap, also called a P-trap, is the looping section of pipe in a sink drain assembly , located just below the sink. The bend in the trap holds a small amount of standing water to prevent sewer gases from re-entering your home. It's required by plumbing code, and is often part of installing a new sink or drain .
When parts of a trap corrode, clogs build up, the standing water evaporates, you notice foul odors, or the joints begin to leak and can't be fixed by tightening the connecting nuts, it's time for a P-trap replacement.
P-Trap Sizes and Materials
Sink drain traps are usually made of white PVC , black ABS plastic, or chromed metal (brass or copper), typically at a 1 1/2-inch diameter for bathroom sinks, and a 2-inch diameter for kitchen sinks, showers, and tubs.
Some sink drain assemblies are made with solvent-glued, rigid pipes and fittings that will need to be cut off and then replaced using a set of adapters. Others use a flexible, accordion-like trap arm or tailpiece extension— but flexible pipes have internal ridges that make them more susceptible to clogging, and should be swapped out for another option when making a replacement.
Before You Begin
When replacing a P-trap, you can purchase individual parts or a drain trap assembly kit. The kit usually includes two or three major components: the trap bend (by itself, it's shaped like a "J") and the trap arm, which has one curved end that connects to the trap bend, and a straight end that connects to the branch drain opening in the wall to form the "P" shape. Some kits may also include a tailpiece extension, as well as additional adapters and other parts your sink's configuration may need.
Source: https://www.thespruce.com/replacing-a-sink-p-trap-2718773