Airfoils are key factors in maximizing the efficiency of turbomachinery. The ideal configuration of the airfoil is engineered to produce significant lift while minimizing drag, all while adhering to specific structural limitations. In this investigation, an innovative algorithm based on unconstrained conjugate gradient techniques to optimize the aerodynamic shape of airfoils is proposed. NACA4412 and NACA2415 airfoils are chosen to be investigated in detail. Bézier parameterisation method is employed to define the design variables. Optimization is conducted utilizing a MATLAB code and the XFOIL panel method-based flow solver to attain the desired aerodynamic outcomes. The optimization process enhanced aerodynamic performance by increasing the lift-to-drag ratio and decreasing the angle of attack for maximum lift-to-drag ratio. An increase of 13.7 % in performance for the NACA 4412 airfoil and 32 % for the NACA 2415 airfoil was achieved. Comparisons with traditional methods demonstrated the efficiency and robustness of the proposed algorithm.