The primary function of the rectum is to act as a temporary storage facility for feces produced by digestion. It gathers and collects waste material from the colon, detecting the presence of stool and signaling the need for its expulsion through nerve pathways. The rectum's muscles orchestrate a controlled process of defecation, ensuring that waste is expelled at appropriate times. Additionally, sensors in the rectal wall can distinguish between gas and solid waste, aiding in the prevention of accidental releases. This organ also plays a role in the absorption of certain substances, including some electrolytes and small amounts of water, which can contribute to maintaining the body's hydration levels.