CPython optimizes memory by pre-allocating and caching integer objects in the range of -5 to 256. When a number within this range is used, Python reuses the existing object, significantly reducing memory overhead and improving performance for frequently accessed small integer values.