Companies primarily pay out profits to shareholders by declaring dividends. Beginning in the 1980s, however, companies started to return more cash to shareholders by buying back stock. When shares are bought back, the shares go into the "treasury stock" line on the balance sheet.

Sometimes, companies buy back stock only to sell it at a later date. These transactions, like all transactions, have to be accounted for. We'll use an example to show you what happens when companies sell treasury stock, and how this affects shareholders' equity.

The accounting behind selling treasury stock
A company can only have treasury stock from buying back stock, so we have to start one step behind, at the point a company buys back stock.

Let's assume Foolish Corporation has been in business for a few years. When it first issued stock, it issued 1,000 shares with a par value of $1, for $5 each.

After a few good years in business, it has some excess cash. It decides its stock is cheap, so it buys back 100 shares at the current market price of $10 each. Thus, the shareholders' equity portion of the balance sheet would look like this. (The items I want you to pay close attention to are in blue and bolded.)

Notice first that it repurchased 100 shares of stock. There are only 900 shares outstanding, versus 1,000 shares issued. 

Also note the existence of treasury stock. The negative-$1,000 balance reflects Foolish Corporation's buyback of 100 shares at a cost of $10 each.

Selling treasury stock
Now let's assume Foolish Corporation needs to raise capital to fund its expansion plans. Its stock has risen in value to $15 per share. The company decides it will sell 50 shares of its treasury stock for $15 each.

To account for this transaction, it will make three changes in its statement of shareholders' equity. The items that changed are bolded and in blue:

First, the "common stock" line is adjusted to show that there are now 950 shares outstanding versus 900 shares in the prior period. Selling 50 shares of treasury stock results in 50 additional shares outstanding.

When the company sold the 50 shares of treasury stock, it received $750 in cash. The shares had an original cost of $10 each, or $500. Thus, the shares were sold at a premium of $250 to their original cost.

The "paid-in capital from treasury stock" line is adjusted to reflect the $250 premium from the sale of 50 shares of treasury stock. The "treasury stock, at cost" line is adjusted to reflect that there are only 50 shares of treasury stock remaining at a cost of $10 each ($500).

That's it. After the appropriate lines are adjusted, total shareholders' equity increases by $750, or the amount of cash it received by selling 50 shares of treasury stock for $15 each. Selling treasury stock always results in an increase in shareholders' equity.

What happens when shares are sold at a discount to their cost
The preceding example shows you what happens when a company sells treasury stock at a premium to cost. The accounting is different if a company sells treasury stock at a discount to its cost.

Remember, Foolish Corporation originally paid $10 to buy back 100 shares. In the last example, it sold 50 shares of treasury stock for $15 each, a $5 premium to cost. At the end of the last example, shareholders' equity looked like this.

Let's build on where we left off to show you what happens when treasury stock is sold at a discount to cost.

Foolish Corporation made some mistakes in planning its budget and realized it needs $100 in cash to fund its operations. Investors punish it for its mistakes, and its stock now trades for only $5 per share.

Unfortunately, Foolish Corporation really needs the money, so it decides to sell 20 shares of treasury stock for $5 each. Remember, this treasury stock was originally purchased for $10 per share.

After selling 20 shares of treasury stock for $5, shareholders' equity would look like this.

Let's make note of the most simple adjustment first: Foolish Corporation sold 20 shares of treasury stock, so those shares have to be added to the number of shares outstanding. There are now 970 shares outstanding.

By selling 20 shares at $5 each, the company takes in $100 in cash. It originally paid $200 for these shares, so the shares were sold at a total discount to their cost of $100. This discount is charged to the "paid-in capital from treasury stock" line in the amount of $100.

The "treasury stock, at cost" line-item must also reflect that there are 20 fewer shares held as treasury stock. We adjust this line by $200 to reflect the original cost of $10 per share of treasury stock sold.

And we're done! But take notice: Even though the treasury stock was sold at a discount to cost, shareholders' equity increases. That's because selling treasury stock results in an increase in cash with no offsetting liability. Thus, shareholders' equity increases by $100. Again, selling treasury stock always results in an increase in shareholders' equity.

And there you have it -- this is how you account for the sale of treasury stock, whether it's sold at a discount or premium to cost. The cost method is the most common method for accounting for treasury stock transactions.

If you're ready to dive into the world of stock investing for yourself, head on over to our Broker Center. We have plenty of resources to help you get started.

This article is part of The Motley Fool's Knowledge Center, which was created based on the collected wisdom of a fantastic community of investors. We'd love to hear your questions, thoughts, and opinions on the Knowledge Center in general or this page in particular. Your input will help us help the world invest, better! Email us at Thanks -- and Fool on!