In this study, the numerical investigation of the natural convection heat transfer around a hot elliptical cylinder inside a cold rhombus enclosure filled with a nanofluid in the presence of a uniform magnetic field is conducted. An immersed boundary method as a computational tool has been extended and applied to solve the problem. The influence of various parameters such as cylinder diameters (a, b), Hartmann number (Ha = 0, 50 and 100), nanofluid volume fraction ($$\varphi = 0 , 2.5\% and 5\%$$
φ
=
0
,
2.5
%
a
n
d
5
%
), and Rayleigh number (Ra = 103, 104, 105, 106, and 107) has been studied. Streamlines and isotherms contours as well as average Nusselt number have been specified for different modes. An equation for the average Nusselt number as a function of mentioned parameters is presented in this paper. The results show that at lower Ra numbers of Ra = 103 and 104, the magnetic field effect is negligible. However, at higher Rayleigh numbers, the average Nusselt number (Nuave) decreases with the increasing Ha number. The maximum decrease in Nuave at Ra = 105, 106 and 107are calculated −8.15%, −23.4% and −27.3%, respectively. An asymmetry-unsteady flow is observed at $${\text{Ra}} = 10^{7}$$
Ra
=
10
7
for Ha = 0. However, at higher Ha numbers a steady-symmetrical flow is formed.