localhost, it's the address of the current machine, accessed through a loopback interface (not through the network adapter - this works even if there is no network chips in the system).
The ip that you get from the router is a different story: it's the address that allows other computer on the network to find you. Well, you can use that ip on the same machine too, but it works differently as before: it's going out to the router and in again (I'm simplifying here, but that's the general idea).
And if you are connected to the internet, you also get another ip from your ISP - the ip by which other computer all over the world find you. However, these two at least refer to the same network adapter (
eth0 or the wireless card or whatever).
localhost is different.
The operating system, the servers and so on... can behave differently when accessed from
localhost. You usually don't have a firewall for that, and many local services have a
localhost interface that is meant simply to communicate with an application. Many times, you will want to test your web server by first hooking it up to listen on
localhost only, so you can check if it works, but other people can't. Then, you can reconfigure to listen on your external ip address and start serving the website (and test again if everything still works).