Double-entry bookkeeping for hackers

Sean Markan

[Thanks to Chris Berkhout for helpful corrections.]


Accountants use a system known as double-entry bookkeeping to track the finances of an organization. Double-entry bookkeeping is a simple idea, but it is difficult to find a clear and concise exposition. After piecing it together from various sources, I decided to write my own explanation, one which I hope will appeal to people who don't know anything about accounting, but who do appreciate the elegance of a well-designed system.

Using accounts to track value and flows of value

First let me remark that everything here applies just as well to personal finances as it does to the finances of an organization. You could, if you desired, use double-entry bookkeeping on your personal finances. But from here on out I'll refer to a hypothetical business.

The most critical (monetary) numbers to track in a business are:

  • the value of your assets
  • the value of your liabilities
  • your income (in a given month, year, etc.)
  • your expenses (in a given month, year, etc.)

Assets are the things you own (cash, stock, property, etc.) or are owed (such as a yet-to-be-received payment for a service you have provided). Liabilities are commitments you have made to pay other parties. For example, in the time between purchasing a service and paying for it, you have a liability for the amount of the bill. A loan is another type of liability.

Obviously your net assets and net liabilities are both defined at any given moment (e.g. "assets at midnight on January 17th"). Income and expenses, on the other hand, are defined over a period of time ("income during the first week of February").

To track assets/liabilities and income/expenses, businesses use a system of "accounts". At any given time, each account has a balance, which starts at 0 and changes as transactions occur. A business will generally have multiple accounts in each account category: for example, asset accounts might include a checking account, a cash account, and an account which tracks the value of a building it owns. Liability accounts might include an account corresponding to the debt on a loan, or an account which tracks how much you currently owe a certain supplier. The net assets of the business will be the sum of all the asset accounts. Likewise with liabilities.

Note that when we use the word "account", we are not talking about bank accounts. Accounts are just records that the company keeps internally. Some of those "internal" accounts will be set up for the purpose of tracking bank accounts, and thus should have basically identical entries to what the bank statement says, but many of the internal accounts (like cash and physical property) have no counterpart at the bank.

Also, it may seem a little odd that income and expense accounts even exist, because the balance of these accounts doesn't "mean" anything. If your cash account says $10, you have $10 in cash. But if your expense account says $10, you don't have $10 of anything. (Instead, you have simply accumulated $10 of expenses since you started keeping track.) Nonetheless, it is standard to have income and expense accounts and track their value over time. Expense accounts simply start at 0 and then you add to them as expenses are incurred. Likewise income accounts start at 0 and become more negative as income is earned. You'll soon see the virtues of this system. (Income and expense accounts do also generally get reset to 0 at the end of the year. We'll explain this below.)

The chart of accounts

Accountants often use the term "chart of accounts" to refer to a list of all your accounts. They also like to number all the accounts. Here's a sample chart of accounts:

  Checking                                  101
  Cash                                      102
  Accounts Receivable
    Bob                                     103
    John                                    104

  Mortgage                                  201
  Accounts Payable                          202
  Loan from Susan                           203

  Income from painting                      301
  Income from woodworking                   304

  Paint                                     401
  Computer equipment                        402
  Electricity                               403
  Taxes                                     404
  Depreciation                              405

(In case you're not familiar with the idea of accounts receivable, it simply refers to money owed to us by people who have purchased our goods or services, but have not yet paid the bill.)

The key principles of accounting

Now we get to the non-obvious, yet elegant, features of accounting. There are two key principles:

  1. Some of your accounts have positive values, and some have negative values.
  2. The sum of all the accounts is zero. (And if it isn't, you made a mistake somewhere.)

Here are the sign conventions for accounts:

assets          positive
liabilities     negative
income          negative
expenses        positive

Assets and liabilities are fairly easy to understand. If you have $100 in cash and other assets, your asset accounts should add to $100. If you have $200 in total debt, your liability accounts should add to $-200.

Income and expenses are a little more surprising. When we earn $100 in income, we decrease the corresponding income account by $100 (so that it gets more and more negative over time). When we spend $100, we increase the expense account by $100 (so that it gets more and more positive over time). You'll see why in a moment. You will also see in a moment why the sum of accounts is always zero.

The general ledger

To track activity on accounts, businesses use what is known as a "general ledger". This is a table which lists all changes to the value of any account (going back all the way to the start of the business), along with the amount of the change and the date on which it occurred. All account values start at 0, so using this table, you can sum up the appropriate entries to compute the value of any account at any time.

Here's an example of the beginning of a general ledger (this is for a company that opened its doors on 1/1/14).

| date   | comments                       | account               | delta |
| 1/1/14 | open checking account          |                       |       |
|        |                                | assets.checking       |   300 |
|        |                                | owner equity          |  -300 |
| 1/2/14 | borrow money from susan        |                       |       |
|        |                                | liabilities.susan     |  -100 |
|        |                                |           |   100 |
| 1/3/14 | buy paint                      |                       |       |
|        |                                |           |  -100 |
|        |                                | expenses.paint        |   100 |
| 1/4/14 | bill bob for painting services |                       |       |
|        |                                | assets.receivable.bob |  2450 |
|        |                                | income.painting       | -2450 |
| 1/5/14 | bob pays for my services       |                       |       |
|        |                                | assets.receivable.bob | -2450 |
|        |                                | assets.checking       |  2450 |
| 1/6/14 | withdraw cash                  |                       |       |
|        |                                | assets.checking       |  -100 |
|        |                                |           |   100 |
| 1/7/14 | partially repay susan          |                       |       |
|        |                                |           |   -50 |
|        |                                | liabilities.susan     |    50 |

Notice that the ledger is organized into transactions. Every transaction affects multiple accounts, and these effects are listed as a unit. For example, if we buy something, that affects both assets and expenses. The asset account decreases by some amount, and the expense account increases by the same amount. (Commonly a transaction affects exactly two accounts, hence the term double-entry bookkeeping.)

Adding up all the entries, we obtain a value for each account as of 1/7/14:

assets.checking            2650
assets.receivable.bob         0                  50
liabilities.susan           -50
income.painting           -2450
expenses.paint              100
owner equity               -300

(Don't worry about the owner equity account just yet, we'll come back to that.)

Again, notice that income and liability accounts have negative values. (In real life people report these numbers without the negative signs, but I'm going to leave them because it's conceptually simpler.)

The golden rule of accounting

The astute reader will notice at this point that the entries within each transaction in our example add to zero, which in turn means that the sum of all accounts is always zero. This is the "fundamental theorem" or "golden rule" of accounting that we mentioned earlier: accounts add to zero. This provides a useful way to check your work.

We can now see why we use negative signs for income and positive signs for expenditures: it makes the accounting equation hold.

Another way to understand income and expenses is that they correspond to assets held by everybody in the world except you. So when you earn income, the net assets of everybody else goes down, and when you spend it, it goes up. Moreover, the fact that accounts always add to the same value (zero) is just an expression of the "conservation of money": when you transact business, money (and other forms of value) isn't created or destroyed, it merely changes hands.

In terms of remembering the rules for what entries are positive and negative, you can use the following mnemonic: assets and liabilities get the signs that seem logical. Income and expenses get the opposite.

Owner equity

Now we can explain the "owner equity" account as well. When the company gets started, the owner equity account represents how much of his own money the owner has put into the company. (And if there are multiple owners, there are separate owner equity accounts which reflect how much each contributed.)

Since the company (in principle) "owes" the owner their investment back, owner equity is a form of liability, and thus it gets a negative sign.

So when an owner opens a checking account for his new business (using $300 of his personal assets), the owner equity account now has -$300: that reflects his stake in the business.

The owner can also take money out of the company at any time (seeing as how he owns it, he is entitled to do this). For example, if he takes $200 out, the accounts change like so:

                          before             after
    assets of company       300               100
    owner equity           -300              -100

One purpose that is served by introducing the owner equity account is that it enables the sum of all accounts to be 0; without it, any time an owner invested money in the business, or took money out, the sum of accounts would change.

As the business conducts business, it hopefully earns a profit. As accounting entries get made, you can see that the "net profit so far" ends up accumulating in the income and expense accounts:

net profit so far = sum of income and expense accounts

Because the owner is entitled to this profit, it then makes sense to shift money from the income/expense accounts to the owner equity account. This is done typically at the end of the year using something called "closing entries" which will be discussed in a moment. After closing entries for a given year are made, the owner equity account then reflects not how much the owner put in to the company, but how much he is now entitled to take out of the company, if he wishes.

Before we discuss these closing entries, let us cover one more topic.

Credit and debit columns

One thing we glossed over when presenting the general ledger was the "debit" and "credit" columns. It is standard practice in accounting to write numbers in two columns (debit and credit), instead of just a single "delta" column. Positive numbers go in the debit column, negative in the credit column (but without the negative sign). This is basically done for readability, as far as I can tell. Here is how our ledger looks when we obey this convention:

| date   | comments                       | account               | debit | credit |
| 1/1/14 | open checking account          |                       |       |        |
|        |                                | assets.checking       |   300 |        |
|        |                                | owner equity          |       |    300 |
| 1/2/14 | borrow money from susan        |                       |       |        |
|        |                                | liabilities.susan     |       |    100 |
|        |                                |           |   100 |        |
| 1/3/14 | buy paint                      |                       |       |        |
|        |                                |           |       |    100 |
|        |                                | expenses.paint        |   100 |        |
| 1/4/14 | bill bob for painting services |                       |       |        |
|        |                                | assets.receivable.bob |  2450 |        |
|        |                                | income.painting       |       |   2450 |
| 1/5/14 | bob pays for my services       |                       |       |        |
|        |                                | assets.receivable.bob |       |   2450 |
|        |                                | assets.checking       |  2450 |        |
| 1/6/14 | withdraw cash                  |                       |       |        |
|        |                                | assets.checking       |       |    100 |
|        |                                |           |   100 |        |
| 1/7/14 | partially repay susan          |                       |       |        |
|        |                                |           |       |     50 |
|        |                                | liabilities.susan     |    50 |        |

Closing entries

It may seem a bit odd to have "income" accounts which just get more and more negative forever, and "expenses" accounts which just grow forever. Accountants apparently agree, and so the convention is to prevent this by resetting them to zero each year. This is done by making so-called "closing entries" in the entry at the end of each year. Closing entries do not reflect any actual transaction, but simply help to keep the books organized.

In addition to resetting income and expense accounts to zero, closing entries shift profit to the owner equity account, so that the owner equity account then represents the true value of the business (or equivalently, how much money the owner is entitled to take out of the business, should he choose to do so).

Closing entries have several other nice effects. First, since income and expense accounts are reset to zero each year, this means that they always reflect year-to-date income and expenses. Second, you can determine from the closing entry what the year's income and expenses were. And finally, as you would expect, closing entries obey the same accounting equation that every other entry does. An example of closing entries is shown below (our business apparently didn't do anything between 1/7 and 12/31).

| date     | comments                       | account               | debit | credit |
| 1/1/14   | open checking account          |                       |       |        |
|          |                                | assets.checking       |   300 |        |
|          |                                | owner equity          |       |    300 |
| 1/2/14   | borrow money from susan        |                       |       |        |
|          |                                | liabilities.susan     |       |    100 |
|          |                                |           |   100 |        |
| 1/3/14   | buy paint                      |                       |       |        |
|          |                                |           |       |    100 |
|          |                                | expenses.paint        |   100 |        |
| 1/4/14   | bill bob for painting services |                       |       |        |
|          |                                | assets.receivable.bob |  2450 |        |
|          |                                | income.painting       |       |   2450 |
| 1/5/14   | bob pays for my services       |                       |       |        |
|          |                                | assets.receivable.bob |       |   2450 |
|          |                                | assets.checking       |  2450 |        |
| 1/6/14   | withdraw cash                  |                       |       |        |
|          |                                | assets.checking       |       |    100 |
|          |                                |           |   100 |        |
| 1/7/14   | partially repay susan          |                       |       |        |
|          |                                |           |       |     50 |
|          |                                | liabilities.susan     |    50 |        |
| 12/31/14 | closing entries                |                       |       |        |
|          |                                | income.painting       |  2450 |        |
|          |                                | expenses.paint        |       |    100 |
|          |                                | owner equity          |       |   2350 |

After this closing entry, the net values in our accounts are

assets.checking            2650
assets.receivable.bob         0                  50
liabilities.susan           -50
income.painting               0
expenses.paint                0
owner equity              -2650

Note how income and expenses have become zero, and the owner equity account reflects the true value of the business.


In the olden days it was standard practice to keep separate documents, one per account, which listed the transactions affecting that account. (Pretty much in the format you see on your bank statement.) These documents were prepared by manually copying entries out of the general ledger, so that the general ledger was always the primary, "authoritative" source of information. (This process was called "posting.") Computers have made the manual posting process unnecessary, obviously, and accounting software will generate an account-specific view on demand.

What's the point of double-entry?

Double-entry accounting follows from a few simple principles. First, there is the fairly obvious principle that you should know what you have, what you owe, where your money comes from, and where it goes. This leads to maintaining accounts for assets, liabilities, income, and expenses. Furthermore, it makes sense to introduce an owner equity account (or accounts, if there are multiple owners) to track how much the owner(s) have invested in the company.

All of these accounts then change over time. It's natural to group related changes into transactions, and have a master list of such transactions. This gives us the general ledger: a single, authoritative, append-only record of a company's financial state.

Moreover, by choosing the positive and negative signs right, we can get the sum of all accounts to be zero, and the sum within each transaction to be zero, providing a useful way to check our work. Moreover, we can be assured we will keep an accurate tally of expenses (important for tax purposes, obviously): to keep our general ledger in sync with our bank statements, we are forced to note every outflow of money, and the corresponding ledger entries won't balance unless we also note an expense.

More reading

For another hacker's perspective on accounting, you might be interested in this article by Martin Kleppmann.

© 2015-2024 Sean Markan -