In any accounting system, sales revenue, retained earnings, and owner’s equity are normally “credit” accounts. As explained elsewhere on this site, credit accounts have negative balances. This means that total sales and earnings (or profits) are recorded as negative numbers, which sounds counter-intuitive to most non-accountants.
These accounts track how much money the company “owes” the owners. When the owners make an original investment in the company (or shareholders buy shares), the company essentially owes that money back to the owners. When profits are earned, those profits, currently in possession of the company, belong to the owners. The company, from an accounting standpoint, does not own any of its assets. Every bit of value the company holds is all balanced either by a debt, or obligation to the owners.
When cash is received from a customer for a sale, the amount in the “cash” account will be increased. Since every transaction in the accounting system requires balancing positive and negative entries, the amount of cash received must be offset by a negative entry, in this case in the sales account.
(While it is true that value may be removed from inventory during the course of the sale, that should be recorded as an entirely separate transaction in the accounting system. After all, the value that is removed from inventory would necessarily be less than the purchase price paid by the customer. If stock purchases are being recorded as inventory rather than directly as cost of sales, an additional transaction must be created to transfer some amount from “inventory” to “cost of sales”.)
So to offset the increase in cash from a sale, an equal amount is removed from the sales revenue accounts, accumulating a negative balance for total sales.
Expenses and cost of sales, on the other hand, are recorded as positive numbers. At the close of the accounting period, the sales amount will hopefully be a larger negative value (the absolute value is greater) than the expenses, so when the two are combined, there is a negative value remaining to be transferred to the Retained Earnings account. The transaction to close the period will have a positive amount for Sales Revenue to bring the balance back to zero, a negative amount for Expenses to bring it back to zero, and a negative amount for Retained earnings equal to the difference (sum of a positive and negative) of the other two.
Retained Earnings, just like Owner’s Equity and other equity accounts, also holds a negative balance. If the profits are paid out to the owners, for example as stock dividends, then the amount is subtracted from the cash accounts (meaning the bank accounts, too), and an equal amount is added to the retained earnings, bringing that negative balance closer to zero.