Metformin is contraindicated in patients with severe renal impairment, acute or chronic metabolic acidosis, and hypersensitivity to the drug. It should be used with caution in patients with heart failure, liver disease, or those undergoing surgery or radiologic studies involving iodinated contrast materials due to an increased risk of renal impairment.