Abstract We present an accurate ab initio description of the magnetic exchange force microscopy (MExFM). As a prototypical system, the antiferromagnetic NiO(001) surface probed with a Fe tip is investigated. The tip–surface interaction is described on two levels. Short-range chemical and exchange forces between the tip apex and the surface atoms are described in the framework of spin-polarized density functional theory while long-range van der Waals forces are considered within a mesoscopic tip model. For the Ni atoms in the NiO surface as well as the Fe atoms of the tip apex, an on-site repulsion U in the transition-metal 3d shells is included. In order to understand the tip–surface interaction, we investigate the changes in the electronic structure of tip and surface versus distance. The resulting frequency shifts and MExFM images are in good qualitative agreement with experimental data.