In geotechnical engineering, drilling fluid, also called drilling mud, is used to aid the drilling of boreholes into the earth. Often used while drilling oil and natural gas wells and on exploration drilling rigs, drilling fluids are also used for much simpler boreholes, such as water wells. One of the functions of drilling mud is to carry cuttings out of the hole.
The three main categories of drilling fluids are: water-based muds (WBs), which can be dispersed and non-dispersed; non-aqueous muds, usually called oil-based muds (OBs); and gaseous drilling fluid, in which a wide range of gases can be used. Along with their formatives, these are used along with appropriate polymer and clay additives for drilling various oil and gas formations.
The main functions of drilling fluids include providing hydrostatic pressure to prevent formation fluids from entering into the well bore, keeping the drill bit cool and clean during drilling, carrying out drill cuttings, and suspending the drill cuttings while drilling is paused and when the drilling assembly is brought in and out of the hole. The drilling fluid used for a particular job is selected to avoid formation damage and to limit corrosion.
Many types of drilling fluids are used on a day-to-day basis. Some wells require different types to be used at different parts in the hole, or for some types to be used in combination with others. The various types of fluid generally fall into a few broad categories: 
- Air: Compressed air is pumped either down the bore hole's annular space or down the drill string itself.
- Air/water: The same as above, with water added to increase viscosity, flush the hole, provide more cooling, and/or to control dust.
- Air/polymer: A specially formulated chemical, most often referred to as a type of polymer, is added to the water and air mixture to create specific conditions. A foaming agent is a good example of a polymer.
- Water: Water by itself is sometimes used. In offshore drilling, seawater is typically used while drilling the top section of the hole.
- Water-based mud (WBM): Most basic water-based mud systems begin with water, then clays and other chemicals are incorporated into the water to create a homogeneous blend resembling something between chocolate milk and a malt (depending on viscosity). The clay is usually a combination of native clays that are suspended in the fluid while drilling, or specific types of clay that are processed and sold as additives for the WBM system. The most common of these is bentonite, frequently referred to in the oilfield as "gel." Gel likely makes reference to the fact that while the fluid is being pumped, it can be very thin and free-flowing (like chocolate milk), though when pumping is stopped, the static fluid builds a "gel" structure that resists flow. When an adequate pumping force is applied to "break the gel," flow resumes and the fluid returns to its previously free-flowing state. Many other chemicals (e.g. potassium formate) are added to a WBM system to achieve various effects, including: viscosity control, shale stability, enhance drilling rate of penetration, and cooling and lubricating of equipment.
- Oil-based mud (OBM): Oil-based mud is a mud where the base fluid is a petroleum product such as diesel fuel. Oil-based muds are used for many reasons, including increased lubricity, enhanced shale inhibition, and greater cleaning abilities with less viscosity. Oil-based muds also withstand greater heat without breaking down. The use of oil-based muds has special considerations, including cost, environmental considerations such as disposal of cuttings in an appropriate place, and the exploratory disadvantages of using oil-based mud, especially in wildcat wells. Using an oil-based mud interferes with the geochemical analysis of cuttings and cores and with the determination of API gravity because the base fluid cannot be distinguished from oil that is returned from the formation.
- Synthetic-based fluid (SBM) (Otherwise known as Low Toxicity Oil Based Mud or LTOBM): Synthetic-based fluid is a mud in which the base fluid is a synthetic oil. This is most often used on offshore rigs because it has the properties of an oil-based mud, but the toxicity of the fluid fumes are much less than an oil-based fluid. This is important when the drilling crew works with the fluid in an enclosed space such as an offshore drilling rig. Synthetic-based fluid poses the same environmental and analysis problems as oil-based fluid.
On a drilling rig, mud is pumped from the mud pits through the drill string, where it sprays out of nozzles on the drill bit, thus cleaning and cooling the drill bit in the process. The mud then carries the crushed or cut rock ("cuttings") up the annular space ("annulus") between the drill string and the sides of the hole being drilled, up through the surface casing, where it emerges back at the surface. Cuttings are then filtered out with either a shale shaker or the newer shale conveyor technology, and the mud returns to the mud pits. The mud pits let the drilled "fines" settle; the pits are also where the fluid is treated by adding chemicals and other substances.
The returning mud can contain natural gases or other flammable materials which will collect in and around the shale shaker / conveyor area or in other work areas. Because of the risk of a fire or an explosion if they ignite, special monitoring sensors and explosion-proof certified equipment is commonly installed, and workers are trained in safety precautions. The mud is then pumped back down the hole and further re-circulated. After testing, the mud is treated periodically in the mud pits to ensure there are the desired properties that optimize and improve drilling efficiency, borehole stability, and other requirements, as listed below.
The main functions of a drilling mud can be summarized as follows: 
Drilling fluid carries the rock excavated by the drill bit up to the surface. Its ability to do so depends on cutting size, shape, and density, and speed of fluid traveling up the well ( annular velocity). These considerations are analogous to the ability of a stream to carry sediment; large sand grains in a slow-moving stream settle to the stream bed, while small sand grains in a fast-moving stream are carried along with the water. The mud viscosity is another important property, as cuttings will settle to the bottom of the well if the viscosity is too low.
Other properties include:
- Most drilling muds are thixotropic (viscosity increase during static conditions). This characteristic keeps the cuttings suspended when the mud is not flowing during, for example, maintenance.
- Fluids that have shear thinning and elevated viscosities are efficient for hole cleaning.
- Higher annular velocity improves cutting transport. Transport ratio (transport velocity / lowest annular velocity) should be at least 50%.
- High density fluids may clean holes adequately even with lower annular velocities (by increasing the buoyancy force acting on cuttings). But may have a negative impact if mud weight is in excess of that needed to balance the pressure of surrounding rock (formation pressure), so mud weight is not usually increased for hole cleaning purposes.
- Higher rotary drill-string speeds introduce a circular component to annular flow path. This helical flow around the drill-string causes drill cuttings near the wall, where poor hole cleaning conditions occur, to move into higher transport regions of the annulus. Increased rotation is the one of the best methods for increasing hole cleaning in high angle and horizontal wells.
- Must suspend drill cuttings, weight materials and additives under a wide range of conditions.
- Drill cuttings that settle can cause bridges and fill, which can cause stuck-pipe and lost circulation.
- Weight material that settles is referred to as sag, this causes a wide variation in the density of well fluid, this more frequently occurs in high angle and hot wells.
- High concentrations of drill solids are detrimental to:
- Drilling efficiency (it causes increased mud weight and viscosity, which in turn increases maintenance costs and increased dilution)
- Rate of Penetration (ROP) (increases horsepower required to circulate)
- Mud properties that are suspended must be balanced with properties in cutting removal by solids control equipment
- For effective solids controls, drill solids must be removed from mud on the 1st circulation from the well. If re-circulated, cuttings break into smaller pieces and are more difficult to remove.
- Conduct a test to compare the sand content of mud at flow line and suction pit (to determine whether cuttings are being removed).
- If formation pressure increases, mud density should also be increased to balance pressure and keep the wellbore stable. The most common weighting material is barite. Unbalanced formation pressures will cause an unexpected influx (also known as a kick) of formation fluids in the wellbore possibly leading to a blowout from pressured formation fluids.
- Hydrostatic pressure = density of drilling fluid * true vertical depth * acceleration of gravity. If hydrostatic pressure is greater than or equal to formation pressure, formation fluid will not flow into the wellbore.
- Well control means no uncontrollable flow of formation fluids into the wellbore.
- Hydrostatic pressure also controls the stresses caused by tectonic forces, these may make wellbores unstable even when formation fluid pressure is balanced.
- If formation pressure is subnormal, air, gas, mist, stiff foam, or low density mud (oil base) can be used.
- In practice, mud density should be limited to the minimum necessary for well control and wellbore stability. If too great it may fracture the formation.
- Mud column pressure must exceed formation pressure, in this condition mud filtrate invades the formation, and a filter cake of mud is deposited on the wellbore wall.
- Mud is designed to deposit thin, low permeability filter cake to limit the invasion.
- Problems occur if a thick filter cake is formed; tight hole conditions, poor log quality, stuck pipe, lost circulation and formation damage.
- In highly permeable formations with large bore throats, whole mud may invade the formation, depending on mud solids size;
- Use bridging agents to block large opening, then mud solids can form seal.
- For effectiveness, bridging agents must be over the half size of pore spaces / fractures.
- Bridging agents (e.g. calcium carbonate, ground cellulose).
- Depending on the mud system in use, a number of additives can improve the filter cake (e.g. bentonite, natural & synthetic polymer, asphalt and gilsonite).
- Chemical composition and mud properties must combine to provide a stable wellbore. Weight of the mud must be within the necessary range to balance the mechanical forces.
- Wellbore instability = sloughing formations, which can cause tight hole conditions, bridges and fill on trips (same symptoms indicate hole cleaning problems).
- Wellbore stability = hole maintains size and cylindrical shape.
- If the hole is enlarged, it becomes weak and difficult to stabilize, resulting in problems such as low annular velocities, poor hole cleaning, solids loading and poor formation evaluation
- In sand and sandstones formations, hole enlargement can be accomplished by mechanical actions (hydraulic forces & nozzles velocities). Formation damage is reduced by conservative hydraulics system. A good quality filter cake containing bentonite is known to limit bore hole enlargement.
- In shales, mud weight is usually sufficient to balance formation stress, as these wells are usually stable. With water base mud, chemical differences can cause interactions between mud & shale that lead to softening of the native rock. Highly fractured, dry, brittle shales can be extremely unstable (leading to mechanical problems).
- Various chemical inhibitors can control mud / shale interactions (calcium, potassium, salt, polymers, asphalt, glycols and oil – best for water sensitive formations)
- Oil (and synthetic oil) based drilling fluids are used to drill most water sensitive Shales in areas with difficult drilling conditions.
- To add inhibition, emulsified brine phase ( calcium chloride) drilling fluids are used to reduce water activity and creates osmotic forces to prevent adsorption of water by Shales.
- Skin damage or any reduction in natural formation porosity and permeability (washout) constitutes formation damage
- skin damage is the accumulation of residuals on the perforations and that causes a pressure drop through them.
- Most common damage;
- Mud or drill solids invade the formation matrix, reducing porosity and causing skin effect
- Swelling of formation clays within the reservoir, reduced permeability
- Precipitation of solids due to mixing of mud filtrate and formations fluids resulting in the precipitation of insoluble salts
- Mud filtrate and formation fluids form an emulsion, reducing reservoir porosity
- Specially designed drill-in fluids or workover and completion fluids, minimize formation damage.
- Heat is generated from mechanical and hydraulic forces at the bit and when the drill string rotates and rubs against casing and wellbore.
- Cool and transfer heat away from source and lower to temperature than bottom hole.
- If not, the bit, drill string and mud motors would fail more rapidly.
- Lubrication based on the coefficient of friction.("Coefficient of friction" is how much friction on side of wellbore and collar size or drill pipe size to pull stuck pipe) Oil- and synthetic-based mud generally lubricate better than water-based mud (but the latter can be improved by the addition of lubricants).
- Amount of lubrication provided by drilling fluid depends on type & quantity of drill solids and weight materials + chemical composition of system.
- Poor lubrication causes high torque and drag, heat checking of the drill string, but these problems are also caused by key seating, poor hole cleaning and incorrect bottom hole assemblies design.
- Drilling fluids also support portion of drill-string or casing through buoyancy. Suspend in drilling fluid, buoyed by force equal to weight (or density) of mud, so reducing hook load at derrick.
- Weight that derrick can support limited by mechanical capacity, increase depth so weight of drill-string and casing increase.
- When running long, heavy string or casing, buoyancy possible to run casing strings whose weight exceed a rig's hook load capacity.
- Hydraulic energy provides power to mud motor for bit rotation and for MWD ( measurement while drilling) and LWD ( logging while drilling) tools. Hydraulic programs base on bit nozzles sizing for available mud pump horsepower to optimize jet impact at bottom well.
- Limited to:
- Pump horsepower
- Pressure loss inside drillstring
- Maximum allowable surface pressure
- Optimum flow rate
- Drill string pressure loses higher in fluids of higher densities, plastic viscosities and solids.
- Low solids, shear thinning drilling fluids such as polymer fluids, more efficient in transmit hydraulic energy.
- Depth can be extended by controlling mud properties.
- Transfer information from MWD & LWD to surface by pressure pulse.
- Chemical and physical mud properties as well as wellbore conditions after drilling affect formation evaluation.
- Mud loggers examine cuttings for mineral composition, visual sign of hydrocarbons and recorded mud logs of lithology, ROP, gas detection or geological parameters.
- Wireline logging measure – electrical, sonic, nuclear and magnetic resonance.
- Potential productive zone are isolated and performed formation testing and drill stem testing.
- Mud helps not to disperse of cuttings and also improve cutting transport for mud loggers determine the depth of the cuttings originated.
- Oil-based mud, lubricants, asphalts will mask hydrocarbon indications.
- So mud for drilling core selected base on type of evaluation to be performed (many coring operations specify a bland mud with minimum of additives).
- Drill-string and casing in continuous contact with drilling fluid may cause a form of corrosion.
- Dissolved gases (oxygen, carbon dioxide,
hydrogen sulfide) cause serious corrosion problems;
- Cause rapid, catastrophic failure
- May be deadly to humans after a short period of time
- Low pH (acidic) aggravates corrosion, so use corrosion coupons[ clarification needed] to monitor corrosion type, rates and to tell correct chemical inhibitor is used in correct amount.
- Mud aeration, foaming and other O2 trapped conditions cause corrosion damage in short period time.
- When drilling in high H2S, elevated the pH fluids + sulfide scavenging chemical (zinc).
- Cementing is critical to effective zone and well completion.
- During casing run, mud must remain fluid and minimize pressure surges so fracture induced lost circulation does not occur.
- Temperature of water used for cement must be within tolerance of cementers performing task, usually 70 degrees, most notably in winter conditions.
- Mud should have thin, slick filter cake, with minimal solids in filter cake, wellbore with minimal cuttings, caving or bridges will prevent a good casing run to bottom. Circulate well bore until clean.
- To cement and completion operation properly, mud displace by flushes and cement. For effectiveness;
- Hole near gauges, use proper hole cleaning techniques, pumping sweeps at TD, and perform wiper trip to shoe.
- Mud low viscosity, mud parameters should be tolerant of formations being drilled, and drilling fluid composition, turbulent flow - low viscosity high pump rate, laminar flow - high viscosity, high pump rate.
- Mud non progressive gel strength[ clarification needed]
Mud is, in varying degrees, toxic. It is also difficult and expensive to dispose of it in an environmentally friendly manner. A Vanity Fair article described the conditions at Lago Agrio, a large oil field in Ecuador where drillers were effectively unregulated. 
Water based drilling fluid has very little toxicity, made from water, bentonite and barite, all clay from mining operations, usually found in Wyoming and in Lunde, Telemark. There are specific chemicals that can be used in water based drilling fluids that alone can be corrosive and toxic, such as hydrochloric acid. However, when mixed into water based drilling fluids, hydrochloric acid only decreases the pH of the water to a more manageable level. Caustic (sodium hydroxide), anhydrous lime, soda ash, bentonite, barite and polymers are the most common chemicals used in water based drilling fluids. Oil Base Mud and synthetic drilling fluids can contain high levels of benzene, and other chemicals
Most common chemicals added to OBM Muds:
Water-based drilling mud most commonly consists of bentonite clay (gel) with additives such as barium sulfate (barite), calcium carbonate (chalk) or hematite. Various thickeners are used to influence the viscosity of the fluid, e.g. xanthan gum, guar gum, glycol, carboxymethylcellulose, polyanionic cellulose (PAC), or starch. In turn, deflocculants are used to reduce viscosity of clay-based muds; anionic polyelectrolytes (e.g. acrylates, polyphosphates, lignosulfonates (Lig) or tannic acid derivates such as Quebracho) are frequently used. Red mud was the name for a Quebracho-based mixture, named after the color of the red tannic acid salts; it was commonly used in the 1940s to 1950s, then was made obsolete when lignosulfonates became available. Other components are added to provide various specific functional characteristics as listed above. Some other common additives include lubricants, shale inhibitors, fluid loss additives (to control loss of drilling fluids into permeable formations). A weighting agent such as barite is added to increase the overall density of the drilling fluid so that sufficient bottom hole pressure can be maintained thereby preventing an unwanted (and often dangerous) influx of formation fluids
Some factors affecting drilling fluid performance are: 
- Fluid Rheology 
- The change of drilling fluid viscosity
- The change of drilling fluid density
- The change of mud pH
- Corrosion or fatigue of the drill string 
- Thermal stability of the drilling fluid 
- Differential sticking
They are classified based on their fluid phase, alkalinity, dispersion and the type of chemicals used.
- Freshwater mud: Low pH mud (7.0–9.5) that includes spud, bentonite, natural, phosphate treated muds, organic mud and organic colloid treated mud. high pH mud example alkaline tannate treated muds are above 9.5 in pH.
- Water based drilling mud that represses hydration and dispersion of clay – There are 4 types: high pH lime muds, low pH gypsum, seawater and saturated salt water muds.
- Low solids mud: These muds contain less than 3–6% solids by volume and weight less than 9.5 lbs/gal. Most muds of this type are water-based with varying quantities of bentonite and a polymer.
- Emulsions: The two types used are oil in water (oil emulsion muds) and water in oil (invert oil emulsion muds).
- Oil based mud: Oil based muds contain oil as the continuous phase and water as a contaminant, and not an element in the design of the mud. They typically contain less than 5% (by volume) water. Oil-based muds are usually a mixture of diesel fuel and asphalt, however can be based on produced crude oil and mud
"Mud engineer" is the name given to an oil field service company individual who is charged with maintaining a drilling fluid or completion fluid system on an oil and/or gas drilling rig.  This individual typically works for the company selling the chemicals for the job and is specifically trained with those products, though independent mud engineers are still common. The role of the mud engineer, or more properly drilling fluids engineer, is very critical to the entire drilling operation because even small problems with mud can stop the whole operations on rig. The internationally accepted shift pattern at off-shore drilling operations is personnel (including mud engineers) work on a 28-day shift pattern, where they work for 28 continuous days and rest the following 28 days. In Europe this is more commonly a 21-day shift pattern.
In offshore drilling, with new technology and high total day costs, wells are being drilled extremely fast. Having two mud engineers makes economic sense to prevent down time due to drilling fluid difficulties. Two mud engineers also reduce insurance costs to oil companies for environmental damage that oil companies are responsible for during drilling and production. A senior mud engineer typically works in the day, and a junior mud engineer at night.
The cost of the drilling fluid is typically about 10% (may vary greatly) of the total cost of drilling a well, and demands competent mud engineers. Large cost savings result when the mud engineer and fluid performs adequately.
The mud engineer is not to be confused with mudloggers, service personnel who monitor gas from the mud and collect well bore samples.
The compliance engineer is the most common name for a relatively new position in the oil field, emerging around 2002 due to new environmental regulations on synthetic mud in the United States. Previously, synthetic mud was regulated the same as water-based mud and could be disposed of in offshore waters due to low toxicity to marine organisms. New regulations restrict the amount of synthetic oil that can be discharged. These new regulations created a significant burden in the form of tests needed to determine the "ROC" or retention on cuttings, sampling to determine the percentage of crude oil in the drilling mud, and extensive documentation. No type of oil/synthetic based mud (or drilled cuttings contaminated with OBM/SBM) may be dumped in the North Sea. Contaminated mud must either be shipped back to shore in skips or processed on the rigs.
A new monthly toxicity test is also now performed to determine sediment toxicity, using the amphipod Leptocheirus plumulosus. Various concentrations of the drilling mud are added to the environment of captive L. plumulosus to determine its effect on the animals.  The test is controversial for two reasons:
- These animals are not native to many of the areas regulated by them, including the Gulf of Mexico
- The test has a very large standard deviation, and samples that fail badly may pass easily upon retesting 
- Petroleum Engineering Handbook, Volume II: Drilling Engineering. Society of Petroleum Engineers. 2007. pp. 90–95. ISBN 978-1-55563-114-7.
- Oilfield Glossary
- Langewiesche, William. "Jungle Law". The Hive. Retrieved 2017-08-28.
- Rabia, Hussain (1986). Oilwell Drilling Engineering : Principles and Practice. Springer. pp. 106–111. ISBN 0860106616.
- "According the change of drilling fluid to understand under well condition". Drilling Mud Cleaning System. 27 December 2012. Retrieved 26 September 2013.
- Clark, Peter E. (1995-01-01). "Drilling Mud Rheology and the API Recommended Measurements". SPE Production Operations Symposium. Society of Petroleum Engineers. doi: 10.2118/29543-MS. ISBN 9781555634483.
- CJWinter. "The Advantages Of Cold Root Rolling". www.cjwinter.com. Retrieved 2017-08-28.
- "10 Tips To Improve Drilling Fluid Performance" (PDF). Drilling Contractor. Retrieved 2017-08-28.
- Moore, Rachel (2017-07-05). "How to become a mud engineer". Career Trend.
- "Methods for Assessing the Chronic Toxicity of Marine and Estuarine Sediment-associated Contaminants with the Amphipod Leptocheirus plumulosus—First Edition". U.S. Environmental Protection Agency. Archived from the original on 15 April 2014. Retrieved 14 April 2014.
- Orszulik, Stefan (2016-01-26). Environmental Technology in the Oil Industry. Springer. ISBN 9783319243344.
- ASME Shale Shaker Committee (2005). The Drilling Fluids Processing Handbook. ISBN 0-7506-7775-9.
- Kate Van Dyke (1998). Drilling Fluids, Mud Pumps, and Conditioning Equipment.
- G. V. Chilingarian & P. Vorabutr (1983). Drilling and Drilling Fluids.
- G. R. Gray, H. C. H. Darley, & W. F. Rogers (1980). The Composition and Properties of Oil Well Drilling Fluids.
- DCS Shale Shaker SUPPLIER. The Drilling Fluids cleaning system.