With knowledge of geometry and density-distribution of topography, the residual terrain modelling (RTM) technique has been broadly applied in geodesy and geophysics for the determination of the high-frequency gravity field signals. Depending on the size of investigation areas, challenges in computational efficiency are encountered when using an ultra-high-resolution digital elevation model (DEM) in the Newtonian integration. For efficient and accurate gravity forward modelling in the spatial domain, we developed a new MATLAB-based program called, terrain gravity field (TGF). Our new software is capable of calculating the gravity field generated by an arbitrary topographic mass-density distribution. Depending on the attenuation character of gravity field with distance, the adaptive algorithm divides the integration masses into four zones, and adaptively combines four types of geometries (i.e., polyhedron, prism, tesseroid and point-mass) and DEMs with different spatial resolutions. Compared to some publicly available algorithms depending on one type of geometric approximation, this enables accurate modelling of gravity field and greatly reduces the computation time. Besides, the TGF software allows to calculate ten independent gravity field functionals, supports two types of density inputs (constant density value and digital density map), and considers the curvature of the Earth by involving spherical approximation and ellipsoidal approximation. Further to this, the TGF software is also capable of delivering the gravity field of full-scale topographic gravity field implied by masses between the Earth’s surface and mean sea level. In this contribution, the TGF software is introduced to the geoscience community and its capabilities are explained. Results from internal and external numerical validation experiments of TGF confirmed its accuracy at the sub-mGal level. Based on TGF, the trade-off between accuracy and efficiency, values for the spatial resolution and extension of topography models are recommended. The TGF software has been extensively tested and recently been applied in the SRTM2gravity project to convert the global 3” SRTM topography to implied gravity effects at 28 billion computation points. This confirms the capability of TGF for dealing with large datasets. Together with this paper, the TGF software will be released in the public domain for free use in geodetic and geophysical forward modelling computations.