Heparin is a naturally occurring anticoagulant that is widely used in the medical field to prevent and treat blood clots. Its primary function is to inhibit the formation of new clots and the growth of existing clots in the blood vessels. It works by activating antithrombin III, which in turn inhibits thrombin and factor Xa, crucial components of the clotting cascade.