Well, if u want to understand it, then u need to know how IP addresses are allocated and allotted. To be concise, there was this big IP address sapce that had to be given to anyone that wants to be online. ICANN controls all the addresses, protocols, well known ports, AS, etc. But to ease up allocation of IP addresses to everyone, RIRs or Regional Internet Registers were founded in 5 major regions of the world:
ARIN (American),
APNIC (Asia Pacific),
AFRINIC (Africa),
RIPE (European) and
LACNIC (Latin American and Carribean).
The RIRs may delegate IPs to LIRs or Local Internet Registers, which in turn allocate IPs to different ISPs. Back when IANA was around and the net was small enough, you can apply for and lease an IP from the RIRs, but it is now impossible because of the lack of allocatable IP. So the only way is to get it from an ISP.
The point is that, each RIR is allocated a fixed range of IP addresses according to their needs. The RIRs, hence keep a register full of information regarding which IP got allocated to which ISP/LIR. This whois database is what is searched when u whois an IP. This is also the reason that u can get only the ISP to which an IP belongs rather than the the person's ID from his IP address when u whois. For the person's ID information, u have to contact the ISP.
Apart from the whois databases, there are other DBs like RADB which can be bought for fast searches locally. But most of the databases are not maintained or updated well. For example, in some databases, my IP will show up as from australia. This might be due to some recent reallocation of IPs between the RIRs.