When you buy a iphone with a contract what does it mean?

When you buy a iphone with a contract what does it mean?

You get a discount on the phone but you have to pay for service from them for 2 years, usually around $60 - $100 per month.

If you cancel early before 2 years they charge you a huge fee.

They subsidize the cost in order to make it more enticing to buy but then you are locked into a 2 year contract in order to pay the cost of the phone over those 2 years.
You can opt out, but to break it will cost some money.

That's effectively it.