The universal answer: It depends.
Some things to consider...
You want to run enough through your gun(s) to make sure it's reliable and you can shoot it well. Some people say 100 rounds, some say 200 rounds. I've got my own protocol for that.
You may want to consider changing out your carry ammo periodically. Some people do it every 6 months, some every year. I aim for 6 months, but I'm usually closer to a year. I've carried ammo daily for 2 years and that ammo fired fine, so there's that.
How much can you spend? Defensive ammo isn't cheap, especially now, when you can find it. I bought a box or two at a time when I had the money, and now I'm pretty well-stocked.
How much space do you have? I live in an apartment, so my storage options are more limited than someone living in a house. I also have to consider the possibility of maintenance people coming into my apartment, so my storage needs to be discreet.
My suggestion would be to consider these aspects, and within those parameters, get as much as you can. Specific numbers will be up to you.
And if push comes to shove, range ammo will do if you can't get any defensive ammo. Not recommended, but as a last resort it'll do. Good HP ammo is better for self defense, but shot placement is still the most important factor.
Just my opinion.