This paper presents an optimization methodology for the design of square and rectangular substation grounding grids with equal conductor spacing, ensuring compliance with IEEE Std. 80-2013 safety criteria while minimizing construction costs to minimum possible limits. The proposed algorithm systematically performed parameters sweeps on all the design variables as stipulated in the standard, including grid burial depth, surface layer thickness, conductor material, conductor size, conductor spacing, and the number and length of ground rods. For optimization, two different cost functions were used: one based solely on the material costs of conductors, rods, while the other incorporated additional factors such as installation, and excavation costs. The algorithm’s performance is evaluated using eight different test grid systems published in the literature, and results were validated with the optimization results obtained from ETAP software. The results demonstrate significant cost reductions while maintaining safe step and touch potentials, offering a practical tool for designing safe, reliable, and cost-effective grounding grids for electrical substations.