I am unable to understand what happens to the phosphates from ATP. What are they used for ?Charging 3' end or 5'end ?
When you ligate two strands of DNA you build up a phosphodiester bond. To do so, you need energy, and this energy for the DNA ligase comes from the ATP (in bacteria this energy can also come from NAD+. The enzyme metabolizes ATP to AMP + PPi and binds the AMP in its active center. Then the AMP is involved in the reaction itself and released afterwards. This page has a few illustrations on this process. If you want to dive really deep into the topic, have a look at this review: