It holds formation pressure with its density, carries cuttings out, cools the bit, and lays a filter cake on permeable rock so the whole mud does not leak away. Water-based, oil-based, and synthetic-based fluids do those jobs with different consequences for shale stability, formation damage, environmental limits, and cost.
Density is the mud weight. The flow properties that carry cuttings and that add to the circulating density are described by plastic viscosity and yield point, read from a viscometer. A fluid that is dense enough but too thick can fracture the well by friction alone. A fluid that is thin enough to pump but cannot carry cuttings fills the hole with a cuttings bed.