There aren't four billion public IP addresses in use. The problem is that in the early days they handed out class A subnets like they were candy, wasting millions of IP addresses with every one.
Incorrect. Getting an address should be cheap like candy, but that is not the problem. Even if they practiced austerity from the beginning, killing Internet adoption before it could start, there would still be a problem.
The actual number of public addresses that can be used is much less than the 4 billion that you get by raising 2 to the 32nd power. Addresses are allocated in power-of-two groups, so an organization that needs 127 computers online and an organization that needs 250 computers will require the same 256-address amount of space. And each network that joins the Internet increases the global routing table that is copied to every important router in the world, so there is an incentive to allocate larger address groups. You can’t just take one address from one 256-address group and give it to another group; you have to transfer an entire group. I think the actual occupancy of addresses is closer to 50%, or 2 billion. We obviously need more than 2 billion computers and devices online, so that’s where NAT comes in.
NAT works because there is a separate pool of 65 thousand port numbers per IP address for individual application connections. Essentially, your computer does not have an IP address, but it has access to another machine that does, and that machine is dynamically allocating its port numbers to your computer’s applications. Each application uses multiple ports. Web browsers, especially, use a lot of ports. To work, your computer eventually needs access to a public address with enough open port numbers to work.
And this particular tactic to stretch out IP addresses is already stretched about as far as it will go. Servers don’t share ports because client programs use the port to find the server program. And the more smartphones and smart TVs and stuff that go into homes, the fewer the number of homes that can be supported on a single real IP address.
No, on a planet with 7 billion people and having a use for multiple addresses per person, IPv4 is just at least a couple orders of magnitude too small. We need to move to IPv6.