Some phones put the coding to run the phone entirely into the phone's system while others use internal coding plus SIM cards (these are more usual now) -- the coding often includes restrictions to a specific provider, like ATT or Verison. Generally when people list a phone as "unlocked" it means the coding has been changed, but people use the term very loosely.
You have to match the phone you want with the carrier you want to buy your time from (whether you contract for the minutes or buy them as you go). So, if you've decided which carrier you want, you might need to buy an unlocked phone or you might need to buy a phone plus a new SIM card. If you want to use the phone in a different place -- say, Europe or Asia -- you can buy a different SIM card.
Also, if your phone is made for 3G, you have to be sure to buy that service. Or a 4G phone for 4G service; they've gotten better lately, so most of them will revert to 3G if 4G is not available, as long as the service provider offers that.
Clear as mud, right? It took me ages to figure it out. I'm still not positive I've got it right, but I think that's the general outline.
More info here: http://www.makeuseof.com/tag/gsm-vs-cdm ... ce-better/ (circa 2014, with a good summary at the end)
and here: http://www.pcmag.com/article2/0,2817,2407896,00.asp circa 2015.
Phones generally hold data on whichever system runs the phone, whether it's the SIM card or the internal memory. I think. You can get a second card (micro SD, not SIM) to hold more data if you want to do that.