How to ssh into a remote computer

I have two laptops, one running Ubuntu (server) and another running Debian (client), and I want to use ssh to log in to the shh server. While on my router’s network, using the private IP address of the server works fine. However, as soon as I leave the network, such as connecting to my phone’s hotspot or using some other network with internet access, I can no longer connect, using either the public or private IP. The service being used to connect is openssh.