When hydrogen ions travels from area of high H+ concentration to areas of low H+ concentration, it gains energy. The difference of concentration is made by the difference of acidity between inside and outside of the cell. The phospholipid of the cell separates the inside and outside.
The hydrogen ion travels through an area called ATP synthase to get to the lower concentration. The synthase collects the energy by the hydrogen ion and use that energy to create the bond between the ADP and P. With that, another ATP is recreated. Note: the hydrogen ion is created by electron transport chain. But that is really not our topic.