In the present work, the natural convection problem in a two-dimensional square cavity partially filled with porous media is simulated by lattice Boltzmann method (LBM). The flow field and temperature field of fluid in the cavity are obtained by numerically simulating. A comprehensive study of natural convection heat transfer is carried out for various values of the vertical porous layer dimensionless width D, of Rayleigh number, of Darcy number, and of porosity. Research results show that in the case of D < 0.1 or D > 0.9, the hot wall average Nusselt number is sensitive to porous layer width. Under the conditions of high Rayleigh number and high Darcy number, the effect of natural convection becomes distinct and the change of porosity with high Darcy number has obvious influence on heat transfer.