In this paper, the effect of using phase change materials in the wall of a building on the required thermal and cooling energy of the building is studied numerically. PCM is placed in one or two cavities in the wall. The building design is organized for both cold and dry and hot and dry environments. First, the effect of the distance between the two chambers on the PCM of the melt was studied using COMSOL software in a time interval of 5 h. In the following, the effects of using a simple wall, a wall with one Cavity of PCM and two Cavity of PCM on the amount of energy required (ENR), on a monthly and annual basis, using Energy Plus software have been studied. The results of this study revealed that the highest PCM of melt occurred at a distance of 0.85 m from the cavities. The use of two cavities of PCM in the building wall has reduced by 40% in the annual thermal energy (TE) required and also achieved a 7.5% drop in the annual cooling ENR in the building, in hot and dry environments. Also, the use of two cavities PCM in the wall, instead of a simple wall, has reduced the amount of annual thermal and cooling ENR for the house in a cold environment, by 20.8% and 22.6%, respectively. In general, in tropical environments, the amount of ENR for cooling has been more than the ENR for heating the interior of the building, while in cold environments, this trend is reversed.