First, I'd like to note that Namecoin and Bitcoin are separate - they share a lot of code, but they have different blockchains and networks.
Let me talk about the problem that Bitcoin solves: double spending. It solves this by having nodes vote with their hashpower on what they think the most accurate picture of the network is. This creates an ordered list of transactions.
How does Namecoin basically work?
It turns out that having an ordered list of transactions is exactly the sort of thing you need to create a naming system that provides all three elements of Zooko's triangle
Registering a domain looks like this:
- You publish a transaction that says, "You can find mysite.bit at 188.8.131.52"
- Other nodes include that into a block.
It's about as difficult to steal your domain name when it has X confirmations as it is to double spend a transaction which has X confirmations.
Doesn't it mean that we will eventually run out of the supply of Namecoins?
That's true, but the supply of nice sounding memorable domain names is so small that it makes sense for there to be a cost to registering domain names en masse.