Every transaction in traditional accounting should meet the “debit and credit” invariant principle. Technically, it is quite simple. The total of amounts at the source is zero. The total of amounts at the destination is zero. The total of trade amounts converted in universal currency is zero.
However, in “real world accounting”, accountants call a positive value a debit. They call a negative value a credit. This way, they do not need to display any negative signs in their reports.
Assets, a positive value, are displayed as a debit. Debts, a negative value, are displayed as credit.
Moreover, they consider that sales income are future profits, that profits are debts to the owner of the company, and that income should thus be considered as a negative value, just like debts. Just the same way, expenses are future losses, which will reduce the capital of the company, i.e. reduce a debt to the owner of the company, and should thus be considered positive values. It is a bit weird at first but consistent.
Income, a negative value, is displayed as credit. Expense, a positive value, is displayed as debit.
Now, where does this debit and credit invariant comes from? The sad truth is that this debit and credit invariant has no well defined rationale. Many companies in the world do accounting without following this invariant, even if accountants in countries of Civil Law hate to hear that.
The only rationale of the debit and credit invariant is to help making sure that every transaction can be partitioned in 2 subsets of opposite total, consistently with the partitioning of accounts introduced later. However, it is not the only way to reach that goal.