How territorial see is determined under the United Nations Convention on the Law of the Sea
The United Nations adopted the United Nations Convention on the Law of the Sea in 1982. It lays down a comprehensive rule of law and systematic order in all the oceans and seas of the world which shall govern the uses of the boundary, water, and natural resource.
The convention says that Every State has the right to establish the breadth of its territorial sea up to a limit not exceeding 12 nautical miles, measured from baselines determined in accordance with this Convention. The outer limit of the territorial sea is the line every point of which is at a distance from the nearest point of the baseline equal to the breadth of the territorial sea. Article 4 of the convention says that the outer limit of the territorial sea is the line every point of which is at a distance from the nearest point of the baseline equal to the breadth of the territorial sea. Article 5 provides Except where otherwise provided in this Convention, the normal baseline for measuring the breadth of the territorial sea is the low-water line along the coast as marked on large-scale charts officially recognized by the coastal State. Article 6 provides In the case of islands situated on atolls or of islands having fringing reefs, the baseline for measuring the breadth of the territorial sea is seaward low-water line of the reef, as shown by the appropriate symbol on charts officially recognized by the coastal State.
With regard to the internal water the convention says Except as provided in Part IV, waters on the landward side of the baseline of the territorial sea form part of the internal waters of the State. Where the establishment of a straight baseline in accordance with the method set forth in article 7 has the effect of enclosing as internal waters areas that had not previously been considered as such, a right of innocent passage as provided in this Convention shall exist in those waters. Article 9 speaks about the Mouths of rivers and it says If a river flows directly into the sea, the baseline shall be a straight line across the mouth of the river between points on the low-water line of its banks.
Article 10 lays down guidelines about bays which says that a bay is a well-marked indentation whose penetration is in such proportion to the width of its mouth as to contain land-locked waters and constitute more than a mere curvature of the coast. An indentation shall not, however, be regarded as a bay unless its area is as large as, or larger than, that of the semi-circle whose diameter is a line drawn across the mouth of that indentation. For the purpose of measurement, the area of an indentation is that lying between the low-water mark around the shore of the indentation and a line joining the low-water mark of its natural entrance points. Where, because of the presence of islands, an indentation has more than one mouth, the semi-circle shall be drawn on a line as long as the sum total of the lengths of the lines across the different mouths. Islands within an indentation shall be included as if they were part of the water area of the indentation. If the distance between the low-water marks of the natural entrance points of a bay does not exceed 24 nautical miles, a closing line may be drawn between these two low-water marks, and the waters enclosed thereby shall be considered as internal waters. Where the distance between the low-water marks of the natural entrance points of a bay exceeds 24 nautical miles, a straight baseline of 24 nautical miles shall be drawn within the bay in such a manner as to enclose the maximum area of water that is possible with a line of that length. The foregoing provisions do not apply to so-called "historic" bays, or in any case where the system of straight baselines provided for in article 7 is applied.
Article 11 speaks about ports as For the purpose of delimiting the territorial sea, the outermost permanent harbour works which form an integral part of the harbour system are regarded as forming part of the coast. Off-shore installations and artificial islands shall not be considered permanent harbour works. It further says that Roadsteads which are normally used for the loading, unloading and anchoring of ships, and which would otherwise be situated wholly or partly outside the outer limit of the territorial sea, are included in the territorial sea.
Read the complete convention:-
https://www.un.org/depts/los/convention_agreements/texts/unclos/unclos_e.pdf