Before you buy a phone, research the heck out of it on XDA forums if you plan on doing anything to it.
Let's use the Galaxy S4 as an example
When released the AT&T model had a locked sim card but unlocked bootloader, unfortunately the first (or second) OTA update locked the bootloader. Those first unlocked ones fetch a serious premium if you can find one that has not been updated. A locked bootloader means even if you root it, you may not be able to install another rom. At best you can use a modified stock rom. While rom builders are getting good at working around the limitation, it's still a limitation. Locked sim means you cannot port out without authorization.
Here is how carriers stack up, at least with Samsung phones as they are the worst. They will work with carriers and lock it down how they wish, other manufacturers may or may not.
AT&T - locked sim and boot loader
Verizon - locked bootloader, unlcoked sim
Sprint - HAHAHA* TL/DR run away.
T-mobile fully unlocked.
You pay a premium for the T-mobile and unlocked because they are unlocked.
Other brands and models have variations, this is the norm for Samsung though. Samsung are also extremely easy to brick and they are extremely unforgiving. LG often plays games with partitioning which can be a nightmare to root, but they are very forgiving when you screw up. HTC is very forgiving if you mess up and, at least they used to, offer an easy way to root. I have no experience with Sony. Beware OnePlus, they do some shady things, they started out well but have gone downhill.
As for Iphone vs Android
Iphone screen to body ratio is/was pathetic, I also hate IOS and how locked down it is, BUT, at least they do proper updates on a regular basis. Android is nice and open, but updates are a hassle unless you root and rom, and even then it's not easy and Google is a bastard about Gapps and spying. I run Android with a custom rom and very limited Google background systems with as much firewalled as I can.
* Sprint not only locks both, but removes the unlock menu in software, this way they can legally tell you it cannot be unlocked and transfer carriers. They planned for this and was doing those to their phones for a bit before the new FTC law, which they helped write, creating this exemption in the process. They were also placing locks on high end models until 2 years of use (a blacklist), and then after the FCC rule change they placed a hold on them insisting even if the phone was paid off that you couldn't port out with the phone until you used it for a full year on Sprint. When I bought my S4 it was free, a month later they placed an ETF hold on it, saying I needed to use it for a year on Sprint contract. I was considering using Sprint prepaid with it, which I had used for 14 years prior but instead I bought a Verizon mainboard (which was compatible) and ported out. I have not looked back and refuse to do anything with that company.