Definition
Every options contract creates two roles: the buyer, who holds the right to exercise, and the seller (or writer), who carries the obligation to honor that exercise. Assignment is the moment that obligation crystallizes — when the seller is notified that a buyer somewhere has exercised, and shares must now change hands at the strike price. For a covered call writer, assignment means delivering 100 shares per contract at the strike and receiving cash. For a cash-secured put writer, it means buying 100 shares per contract at the strike using the cash that was set aside.
Exercise and assignment are two sides of the same transaction. When a buyer files an exercise notice, the Options Clearing Corporation (OCC) receives it, then randomly selects a broker holding short positions in that contract. The broker, in turn, randomly assigns one of its short customers. The seller has no control over whether or when they are picked — only the contract's status (in-the-money, deep ITM near a dividend date) influences the likelihood.
Assignment overwhelmingly happens at or just after expiration, when in-the-money options are automatically exercised by the OCC. Early assignment — exercise before expiration — is rare and typically only economically rational in narrow cases: deep ITM calls on a stock about to pay a dividend, or deep ITM puts where the time value has collapsed below the carry cost of the strike's cash.