How does a router makes difference between a public IP and a local IP
As far as I understand there is a subnetwork mask, which reroutes the traffic. But suppose I have a router LAN which uses as local IP's the numbers between 192.168.1.0 and 192.168.1.255. Now suppose I want to connect to 192.168.1.5, but not the local one, but the one 'real' IP on the internet. Is this possible?
GhislainG is right
There are IP addresses that are setup for private use which you will not find on the internet itself or let say the WAN (Wide Area Network) and you will notice that everyone that has a router has the same IP address range as you or maybe a different block
They are as follow:
10.0.0.0 - 10.255.255.255 (Most common for business use)
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255 (Most common for home use)
However, when you are using a router, the internet does not really see the IP address from your computer, it sees the IP address that was assigned to your router from your ISP, The router uses whats called a NAT (Network Address Translation) to communicate between the both.
So best way to see it is, your router has created an internal network with it's own IP address range of 192.168.1.x and it is also connected to the network of your ISP with the IP address from the ISP. When your computer sends a request to the router, the router checks the IP address, if it is with in 192.168.1.x it knows to keep the request internal and will search it's list of IPs to see which computer has that IP address, of the IP address is not from the internal ones, then it sends the request to the NAT, the nat acts as a bridge between your internal network and the WWW, it will consult the DNS listing which again is an IP address provided by your ISP and it will then it will forward the request to your ISPs router and so forth.
When the request comes back, it has the IP address of your ISP that was given to the router, when the router gets it back, it has a listing of which internal IP address requested certain information so it has a way to keep track of lets say it's own internal mail. When it arrives it checks to see who ordered it and then routs it to the computer with the correct address.
So your internal IP address given to your computer, never really communicates to the outside world, the router does it on your behalf. When you play an online game with a friend and you both have routers, it is possible that both of you have the same internal IP but the computers never know that and will never give you an IP address conflict with an outsider, because only the routers are talking to each other with their own ISPs IP address.
I tried to make it easy and short to understand, it can get pretty complicated LOL but I hope this helps.