First of all, there does not need to be any earnest money associated with a real estate sale.
Secondly, over many years, a convention has evolved which states that the usual earnest money payment is 10% of the sale. Remember, there is no requirement for any standard percentage of the sale for the earnest money amount.
Real estate firms like a 10% amount, because they are assured that there is enough in the earnest money escrow account to pay their commissions. Sellers like the $10$ amount because if the buyer defaults, the seller can take the earnest money as liquidated damages.
Now to the closing. The seller's agent (Sponsoring Broker in Illinois) usually holds the earnest money in an the Sponsoring Broker's escrow account, although the earnest money could be held by the seller's or buyer's lawyer (they all have escrow accounts) or a title company.
If the seller's agent holds the earnest money, he writes three checks out of the escrow account and brings them to the closing. If the earnest money is 10% of the sale, and the commission is 6% to be shared equally, the first check is made out to the seller's firm for 3%. (The escrow account held by the seller is separate from his operating account, by law.) The second check is made out to the buyer's brokerage firm for 3% and the third check is made out to the seller for the remaining 4%. The settlement statement will credit the buyer with the 10% earnest money, but the settlement statement will also indicate that 3% shall be paid to the seller's broker and 3% paid to the buyer's broker.
Variations of this procedure occur across the country, and at times the seller and buyer broker's commission checks are cut by the Title Company handling the closing.