A numerical investigation has been performed to analyze the effect of magnetohydrodynamic natural convection flow in a differentially heated hexagonal enclosure having a tilted square block filled with CuO/water nanofluid. The horizontal walls of the cavity and tilted walls of the obstacle are uniformly heated of temperature $$\hbox {T}_\mathrm{h}$$ while the inclined walls are kept at constant temperature $$\hbox {T}_\mathrm{c}$$ . The governing conservation equations of the physical problem have been solved using finite element method based on Galerkin weighted residual technique and obtained numerical results are presented graphically in terms of streamlines, isotherms, average Nusselt numbers, mid height horizontal and vertical velocities, average temperature and average velocity of nanofluid for a range of Rayleigh number ( $$10^{3} \le { Ra} \le 10^{6}$$ ), Hartmann number ( $$0 \le { Ha} \le 70$$ ) and solid volume fraction ( $$0.1\% \le \phi \le 5\%$$ ) to show the flow structures and temperature characteristics. It is found that the flow fields and temperature distributions are influenced significantly for the effect of pertinent parameters. In addition, overall heat transfer rate enhanced due to higher values of Ra and $$\phi $$ along with lower value of Ha. Comparisons of the present results with the previously published results on the basis of special cases are performed and found to be in good agreement.