IPv4 uses 32-bit addresses which limits the address space to around 4 billion addresses. It allocates addresses into classes (A, B, C) but this led to inefficient allocation. Subnetting and CIDR were developed to allow more flexible allocation of addresses and reduce routing table sizes. Subnetting divides classes into smaller subnets, while CIDR ignores classes and allows allocation on any bit boundary. This helped slow the growth of routing tables and address exhaustion.