This study delves into the convective heat transfer phenomena within a square cavity that houses a porous medium, analyzing the effects of Darcy (Da) and Rayleigh (Ra) numbers on the thermal and fluid dynamic behavior within the system. Utilizing a combination of computational fluid dynamics (CFD) and the finite element method (FEM), the research focuses on steady-state, laminar flow conditions in two dimensions. The cavity, which is impermeable at its boundaries, contains a centrally located square region filled with a porous, isotropic material. The thermal environment is controlled with insulated horizontal walls and vertically positioned walls that experience sinusoidal temperature variations. The study examines how variations in the permeability of the porous medium (Da numbers ranging from 10−1 to 10−4) and the buoyancy-driven flow strength (Ra numbers spanning from 102 to 105) influence the velocity fields and heat transfer rates, with results expressed through Nusselt number (Nu) distributions. The findings reveal that higher Ra numbers, particularly at 105, significantly intensify convection within the cavity, thereby boosting local rates of heat transfer, especially in the central vertical section. The research identifies that optimal flow resistance in the porous medium occurs within the Da number range of 10−3 to 10−4. These insights are critical for advancing thermal management techniques, particularly in the natural cooling of electronic devices and improving insulation methods.