Heparin is an anticoagulant (blood thinner) that prevents the formation of blood clots. Heparin is used to treat and prevent blood clots caused by certain medical conditions or medical procedures. It is also used before surgery to reduce the risk of blood clots.