AbstractDue to the energy storage lifetime effects of the power allocation, there is a large space to improve the economy of the electric‐hydrogen hybrid DC microgrid. This paper provides an optimal control method based on the mutual learn salp swarm algorithm (MLSSA) in real‐time, which aims to enhance the economy and extend the system's service life. In order to realize the economic operation, operation cost and degradation cost of battery and hydrogen system are considered as the objective function first. Then, salp swarm algorithm based on mutual learn strategy is introduced to obtain optimal economy power allocation results in real‐time with higher convergence speed and increased accuracy. In addition, the proposed method also maintains the battery state of charge (SOC) and state of hydrogen charge (SOHC) within a proper range to guarantee the stable operation of the system. Finally, the results including power results, cost analysis and degradation rate analysis of the MATLAB/Simulink show that the proposed method is more economically beneficial than the non‐considering degradation cost strategy.