Automatic identification system - Wikipedia
https://en.wikipedia.org/wiki/Automa...ication_System
The automatic identification system (AIS) is an automatic tracking system used on ships and by vessel traffic services (VTS) for identifying and locating vessels
Yes, the one for ships is a law. So I suppose submarines don't have one for navigation, but they do have emergency orange beacons that flash all the time when navigating.