This happens because oil and water don’t mix.
When a duck is swimming or out in the rain, the bird secretes an oil from glands near its tail. With its bill, the duck rubs the oil over its body.
The oil keeps the water from soaking through the duck’s feathers, making the bird “waterproof.”