The closing entry or entries at the end of the accounting year will include 1) a debit to each revenue account that has a credit balance, 2) a debit to each gain account, and 3) a debit to each contra expense account. The amount of each debit entered into an account will be the amount of each account's credit balance.
The closing entry or entries will also include 4) a credit to each expense account that has a debit balance, 5) a credit to each loss account, and 6) a credit to each contra revenue account such as sales returns and allowances. The amount of each credit entered will be the amount of the debit balance in each account.
If the debits to the revenue, gain, and contra expense accounts have a total that is greater than the closing entry credits to the expense, loss, and contra revenue accounts, the corporation had a positive net income. The net income amount will be credited to Retained Earnings, either directly or through an Income Summary account.
Let's illustrate this with some numbers. Assume that the revenue, gain, and contra expense accounts had credit balances totaling $600,000; and the expense, loss, and contra revenue accounts had debit balances that totaled $530,000. This will require closing entries resulting in $600,000 of debit amounts, $530,000 of credit amounts, and a $70,000 credit to Retained Earnings. If the expenses and losses were greater than the revenues and gains, there will be a debit to Retained Earnings.
The purpose of the closing entries is to end up with a zero balance in every temporary account before starting the next accounting year.