This paper presents the solution of optimal power flow using the Hamiltonian optimization technique. The proposed Hamiltonian technique is employed for power loss optimization which is very critical issue in optimal power flow. Power loss across transmission lines is a major concern in the recent electrical power crisis. Therefore, the scope of this work is to minimize the power loss effectively and to evaluate the performance and analyze the effectiveness of the Hamiltonian optimization technique. The control variables chosen for this work are voltage magnitude of generator buses, the reactive power generation from the buses and static VAR compensators, voltage angle of the slack bus, and active, reactive power of load buses. The minimum power loss value by using HOP for IEEE 30-bus and 57-bus systems are 3.38 MW and 10.354 MW, respectively. The basic reason for such improved result is the use of Set to Middle Approach (SMA) instead of Set to Limit Approach (SLA) for tackling inequality constraints on control variables. MATLAB is used to simulated the IEEE 30-bus and IEEE 57-bus system to test and analyze the effectiveness of the proposed technique.