<span lang="EN-US">Adaptation of renewable energy is inevitable. The idea of microgrid offers integration of renewable energy sources with conventional power generation sources. In this research, an operative approach was proposed for microgrids comprising of four different power generation sources. The microgrid is a way that mixes energy locally and empowers the end-users to add useful power to the network. IEEE-14 bus system-based microgrid was developed in MATLAB/Simulink to demonstrate the optimal power flow. Two cases of battery charging and discharging were also simulated to evaluate its realization. The solution of power flow analysis was obtained from the Newton–Raphson method and particle swarm optimization method. A comparison was drawn between these methods for the proposed model of the microgrid on the basis of transmission line losses and voltage profile. Transmission line losses are reduced to about 17% in the case of battery charging and 19 to 20% in the case of battery discharging when system was analyzed with the particle swarm optimization. Particle swarm optimization was found more promising for the deliverance of optimal power flow in the renewable energy sources-based microgrid.</span>