A pawn on the seventh rank with a clear square in front of it is not really a pawn any more. It is a queen with one move of paperwork left to do.
8
g That move is written e8=Q, and the whole thing counts as one move. The pawn is lifted off, the queen goes down on the same square, and the clock is pressed once. A piece worth one point has become a piece worth nine, which is why a passed pawn two squares from the end is often stronger than a rook, and why so many endings come down to who can shepherd one through.
You write the move as the destination square, an equals sign, and the letter of the new piece: e8=Q. If you promoted by capturing, the pawn’s file goes in front as usual, so bxa8=N. Check and mate signs go on the end, e8=Q+ and e8=Q#. Older books write e8Q or e8(Q) and mean exactly the same thing.
What has to happen on the last rank
Three things, all part of the same move.
The pawn arrives on the far rank: rank 8 for White, rank 1 for Black. It can get there by pushing or by capturing, and capturing is the more common route, since something is usually standing in the way.
It is exchanged for a new queen, rook, bishop or knight of its own colour. Not a king, not a pawn, not a piece of the opponent’s colour.
The new piece takes effect at once. No pause, no waiting move.
Promotion is not an option you may decline. Article 3.7 of the FIDE Laws uses the word must: there is no legal position with a pawn on the eighth rank, and an arbiter will not let you leave one there while you think about it.
A new piece is not marked or tracked in any way. Once your queen is standing on a8 she is simply a queen, no different from the one that started on d1, and nothing in the score sheet or the rules ever treats her as second class.
One thing beginners always ask: no, you do not need to have lost a queen first. The choice is not restricted to captured pieces. You can have your original queen on d1 and a brand new one on a8 at the same time, and two queens is a perfectly ordinary endgame position.
Four pieces, and the choice is yours
Queen, rook, bishop, knight. Nine points, five, three and three, so the queen is right almost every time and there is no reason to spend clock on the decision. The full list and what is excluded is worth a minute of reading, because the exclusions matter as much as the list.
Taking anything other than a queen is called underpromotion, and it has exactly two good reasons behind it. A knight, because a knight goes to squares a queen cannot and can arrive with check. Or a rook, because a new queen would stalemate the enemy king and a rook does not.
The knight is not a joke
a Look at what a queen would have done there. Promote to a queen and White has a queen and Black has a queen, and the position is a fight. Promote to a knight and the fork wins the black queen outright, because a knight on e8 attacks both g7 and c7 while a queen on e8 attacks neither.
That is the whole case for the knight in one picture. It is not a party trick, it is the one piece whose moves a queen cannot copy, so it is the one promotion that can do something a queen cannot. If you want more of these, they are the bread and butter of promotion puzzles, and the same eye that spots them spots ordinary knight forks.
Doing it properly at the board
In a tournament game, physical procedure matters. Play the pawn to the eighth rank, take it off, put the new piece on that square, and only then press the clock. Do not press the clock with a pawn still standing on a8. Do not announce a queen and leave the pawn there. The move is not finished until the right piece is on the right square.
If there is no spare queen in the box, and there usually is not, stop the clock and ask the arbiter for one. That is what arbiters are for, and there is a page on promoting without a spare queen covering what to do and what not to improvise. The short version: an upside-down rook is a rook.
Online, none of this is your problem. A little menu of four pieces appears, or the site queens for you automatically if you have set it to. Just know that the auto-queen setting will queen in the position where a knight wins on the spot, so leave it off if you are playing anything slower than bullet.