A P-trap is a U-shaped section of pipe located below a sink. Its function is to capture and retain enough water, which acts as a barrier to prevent sewage gases and odors from entering the bathroom.