This question already has an answer here:
- How do malloc() and free() work? 14 answers
To free memory, you don't generally need to say how much memory you want to free. The allocator already knows how much it gave you, and remembers that. The address of the allocated memory serves as a sort of "key" in the allocator's internal bookkeeping data structures. So all you need to do is give the address of the memory you want to free, and the allocator knows which memory you're talking about.
To be clear: there's no such thing as "partially freeing" some memory. You can't point into the middle of some allocated memory and say "free 100 bytes here". You release precisely what you acquired, no more and no less.
realloc is just a combination of
memcpy, if you will, perhaps with a small optimization opportunity that allows an existing allocation to "grow" without moving the data. But the idea is the same.