The vast majority of exercises are automatically carried out based on the closing settlement price on the contract expiration date. If you, as the option purchaser, need to exercise early or waive your rights to exercise, please refer to [How can I early exercise options or waive my exercise rights]
As the option purchaser, if the option is out of the money on the expiration date, the expired option will have no value and there will be no exercise taken place; if the moneyness of the option is equal to or higher than $0.01, the option will be automatically exercised, which will be completed in the form of a physical delivery.
As the option seller, when the option is exercised by the purchaser, the option clearing house will randomly match the open short position with the exercised option. If your account is assigned, you must either deliver the underlying stock (in case of a call option) or buy the underlying stock (in case of a put option).
Generally speaking, in-the-money options are exercised when they expire. If you are short an in-the-money option on the expiry date, you will most likely be assigned. The purchaser may also choose to waive the exercise rights or early exercise the option regardless of the actual moneyness.