Replace-by-Fee (RBF) is a protocol-level mechanism that allows users to replace unconfirmed Bitcoin transactions with a new one. This can be done for a variety of reasons, such as if the original transaction had a low fee, and the user wants to increase the amount of fees included in the transaction.
It can also be done if the original transaction was stuck due to network congestion, and the user wants to attempt to get it through quicker. The process of using RBF requires two transactions: the original transaction and a replacement transaction. The original transaction will have a Sequence Number (nSequence) that indicates that it is replaceable, while the replacement transaction will include the same inputs and outputs as the original transaction, but will have a higher fee.
Since the nSequence number is attached to the transaction, the network will be able to identify the replacement transaction as valid. When a miner receives the replacement transaction, they will replace the original transaction with it and include it in a block.
However, this is not guaranteed – some miners may choose to not recognize transactions that use RBF, as they may see it as malicious behavior. Nonetheless, RBF can be an effective way for users to get their transactions through quickly if they are willing to pay more fees.