The present work examines numerically using a finite element scheme the magnetic field on natural convection within I-shaped wavy-walled enclosure filled by a nanofluid and porous medium. The porous medium had been modeled by the Darcy–Brinkman model while a single phase model treats the nanofluid. The thermal equilibrium model had been applied between the nanofluid and porous medium under steady-state conditions. The enclosure contains a trapezoidal heater attached to its bottom wall with an internal heated circular cylinder immersed in the enclosure. The two wavy walls are kept at a cold temperature, while the rest walls are insulated. The influence of the Rayleigh number , Darcy number , Hartmann number , nanofluid loading , magnetic field inclination angle , trapezoidal heater length , location of the trapezoidal heater , and position of the circular cylinder on fluid flow and heat transfer have been discussed deeply. It is obtained that the Nusselt number increases as the Rayleigh number, Darcy number, magnetic field angle increase, and the Hartmann number decreases. Also, for better heat transfer it is obtained that the center location gives the highest value at . Also, the location of the trapezoidal heater in the right region at reveals the best location in terms of heat transfer improvement.