In this study, the lattice Boltzmann method was used to solve the turbulent and laminar natural convection in a square cavity. In this paper a fluid with Pr = 6.2 and different Rayleigh numbers (Ra = 103, 104,105 for laminar flow and Ra = 107, 108,109 for turbulent flow) in the presence of a magnetic field (Ha = 0, 25, 50, and 100) was investigated. (Results show that the magnetic field drops the heat transfer in the laminar flow as the heat transfer behaves erratically toward the presence of a magnetic field in a turbulent flow. Moreover, the effect of the magnetic field is marginal for a turbulent flow in contrast with a laminar flow.The greatest influence of the magnetic field is observed at Ra = 105 from Ha = 0 to 100 as the heat transfer decreases significantly.