The inhibitory effect of spent coffee grounds (SCG) tannin extract as a corrosion inhibitor on ferrous metal in acid and alkaline media has been carried out. The results of evaluation the corrosion rate (CR) and inhibition efficiency (IE) in this study used the weight loss method. The Internasional Standard (SI) unit for calculating the corrosion rate was mm/year (mmpy). The results of the characterization of SCG tannin extract using Fourier Transform Infrared Spectroscopy (FTIR) showed that the functional groups were O-H, aliphatic C-H, C=O ester, aromatic C=C, C-O-H, and C-O-C ether which indicated the presence of tannin compounds in SCG. The results of the research showed that the maximum concentration of SCG tannin extract in inhibiting corrosion in acidic medium was 1000 ppm with an average CR of 2.2520 mmpy and an IE of 29.23%, while in alkaline medium it was 1000 ppm with an average CR 0.0592 mmpy and IE 50.93% for 5 days of soaking time, respectively. The surface morphology of the corroded ferrous metals was monitored with a USB digital microscope at 1000x magnification.