The whole key fob with detachable tangible key or just tangible key? If's it the former then it's a dealer item. If it's the latter, a locksmith shop can do it. Perhaps Lowes or Home Depot also, but I wouldn't trust Walmart.
I am not sure of the cost to replace the Mazda key fob. My wife lost her Prius fob and it cost about $275 including programming at the Toyota dealership. We found that buying a (new) fob off ebay and having the dealership program to be the most cost effective. I think we saved about $50 doing it this way.
If your dealer gives you good service, go there, but any good Locksmith should be able to make keys for your car. Might help if you post up make, model, and year, then you can get some more specific advice. Get 2 sets, it won't cost 2X what one set would cost, put the spare set in a safe place where you won't lose it.