This paper develops a recent methodology based on social spider optimizer (SSO) to determine the optimal sizing of a hybrid renewable energy sources (RESs) integrated microgrid (MG). It comprises photovoltaic (PV), wind turbine (WT), battery, diesel generator (DG), and inverter. The cost of energy (COE) is proposed as fitness function. The objective of the proposed SSO is to determine three design variables which are number of PV panels, number of WT, and number of battery autonomy days such that COE is minimized. Additionally, an energy management strategy is presented. Loss of power supply probability (LPSP) is considered to confirm the reliability of operation. The selection of SSO is due to its simplicity in construction and requiring less controlling parameters. The proposed MG is installed in a remote area at Aljouf region in the northern of Kingdom of Saudi Arabia. Annual data of irradiance, wind speed, and temperature are recorded. The SSO results are compared to Harris Hawks optimizer (HHO), Grey Wolf Optimizer (GWO), Multi-Verse Optimizer (MVO), Antlion Optimizer (ALO), and Whale Optimization Algorithm (WOA). The results obtained show that the proposed approach provides the best optimal configuration of hybrid RESs compared to HHO, GWO, MVO, ALO and WOA with COE of 0.1349 $/kWh and LPSP of 0.01714. Moreover, sensitivity analysis with sizing different topologies of MG including PV/Battery/DG, WT/Battery/DG, and PV/WT/ Battery/DG is presented. The best COEs are obtained via SSO achieving 0.2180 $/kWh for the first topology and 0.2161$/kWh for the second architecture. Furthermore, sensitivity analysis is also presented to investigate the effect of design variables on COE. The experimental results confirm the superiority of the proposed approach in designing reliable and costless microgrid. INDEX TERMS Optimal sizing of hybrid RESs, microgrid, social spider optimization.