A copolymer and polymers were synthesized by chemical oxidative polymerization using ammonium persulfate as an oxidant in hydrochloride aqueous medium. The resultant copolymer and polymers were characterized by Fourier transform infrared (FTIR), UV–vis spectroscopy, XRD and TGA analysis, which reveals a significant improvement in the thermal stability of the copolymer. The copolymer is soluble in various organic solvents such as DMF, DMSO, THF and acetonitrile. The performance of this copolymer as corrosion inhibitor for carbon steel corrosion in 3% NaCl solution was evaluated by potentiodynamic polarization and electrochemical impedance spectroscopy (EIS) techniques. The copolymer acts as an effective corrosion inhibitor for carbon steel. The inhibition process is attributed to the formation of an adsorbed film of copolymer on the metal surface which protects the metal against corrosion. The experimental results indicate that copolymer has good corrosion inhibition performance and the protection efficiency increased with increase in inhibitor concentration. The molecular structure effect on the corrosion inhibition efficiency was investigated using DFT calculations. The parameters for the structural and electronic systems were calculated and discussed. The obtained results show that the experimental studies agree well and confirm that the copolymer is the good inhibitor.