Longitudinal electron bunch length plays a significant role in single-pass free-electron lasers (FEL), as the high-gain FEL process depends strongly on the high peak current of electron bunches. Longitudinal electron bunch length was measured by detecting the interferogram of coherent transition radiation generated by electron bunches using a THz interferometer and a Golay cell (spectral range 0.02–20 THz) at Shanghai X-ray free-electron laser. The detailed process of measurement and data analysis are discussed herein. Furthermore, the electron bunch length was estimated based on the dispersive strength $$ R_{56} $$ of the bunch compressor and the energy spread $$ \delta $$ of electron bunches, which were obtained via experiments. The comparison showed that the measured bunch length was consistent with the estimated bunch length.