The #1 rule of upgrades is to not believe most of what is said and written about them. There may have been a time (decades ago) when upgrades were at the discretion of the gate or flight crew, and being pleasant and well-dressed might work. These days, some airlines don't even have a premium cabin, and those that do have strict rules about upgrades.
There are three main types of upgrade: advance (confirmed), pre-departure paid, and operational. Advance upgrades are confirmed (you have the upgrade for sure) in advance of the flight check-in time. Pre-departure paid are offered by the airline on-line or at the airport, generally within 24 hours of the flight. Operational upgrades are done by the airline when needed for operational reasons, usually because the cabin is oversold.
For most flights, upgrades can be confirmed before the flight using cash (pay the higher fare), miles, or an upgrade instrument. You earn the miles or upgrade instrument by flying a lot with the airline, using an affiliated credit card, transfer or reciprocity with a hotel or other airline program, etc. For domestic flights, most U.S. airlines offer complimentary (completely free) space-available advance upgrades to their high-status flyers (those who fly a lot), although the rules vary from airline to airline. Few airlines offer any sort of complimentary upgrade for international flights.
Pre-departure paid upgrades are offered by some airlines either when the premium cabin has a lot of empty seats, or when the cabin you booked is oversold. Some airlines offer these upgrades on-line, often at 24 hours before the flight. Some offer them at the airport, either at a kiosk or at the check-in or gate agent. Some airlines post signs or make announcements informing passengers that these upgrades are available and indicating the cost, while others will offer them if asked but won't announce them. The cost is usually fixed based on several flight distance bands (e.g., up to 500 miles, 500-2999 miles, 3000 miles and over).
Operational upgrades are done by airlines when they need to for operational reasons, which is usually because the cabin is oversold but a higher cabin has empty seats. Most airlines have detailed and specific rules for how passengers are selected for operational upgrades, which usually are based on frequent-flyer status, if they are connecting or not, if they were previously subject to a delayed, cancelled, or other problem flight, etc. In some cases, a multi-cabin airplane may need a multi-cabin "roll," where passengers might be moved from business to first, from premium economy to business, and from coach to premium economy, to accommodate all passengers needing to be on the plane.