One major criterion in the selection of wind farm location is the cost of energy (COE). COE is the cost of producing 1 kWh electric energy on an annual basis. Mathematical model of COE includes site‐specific constants (such as reference height, mean wind speed, shape factors, wind shear coefficient, average temperature, and turbine altitude) and wind turbine parameters (such as maximum power coefficient, total loss of energy, cut‐in/cut‐off wind speed, rated wind speed, rated power, and the fix charge rate). In this work, we evaluate the COE of an onshore wind farm located at Dumat Al‐Jandal (Saudi Arabia) according to the hub height and rotor size. The 99 Vestas turbines can be mounted at a hub height ranging from 105 to 166 m with available rotor diameters of 105, 112, 117, 126, 136, 150, 155, or 163 m. Particle swarm optimization with a normal distribution is used to optimize the COE. Results show that COE is varying around the average value of $0.029335/kWh by ±$0.00021/kWh. The minimum COE was achieved with a rotor diameter of 150 m at hub height of 105 m. COE increases with the increase of hub height. At 105 m‐hub height, COE is almost the same, with a variation of 0.03% (It ranges between $0.029125/kWh and $0.029133/kWh). COE is more sensitive to rotor size than hub height. This investigation revealed that the COE estimation is in a range of 39%–48% greater than that announced COE by the developing project consortium.