When you set up your online brokerage account, the most common type of brokerage account type is called a cash account. But many online investors request a margin account that lets them buy stocks with borrowed money.

Buying stock on margin isn’t for the faint of heart. Remember, if you borrow money, you must not only pay interest on that cash but also pay back the money you borrowed even if the stock goes down. Buying on margin is generally a good idea only if you’re a highly risk-tolerant investor.

As is the case anytime you borrow to invest, buying stock on margin can boost your profit when you’re right and sting badly when you’re wrong. When you buy a stock that goes up, using margin, you can boost your returns. But if you bet wrong and buy one that goes down, margin magnifies your loss. To understand why, take a look at the following example.

Imagine buying 100 shares of a stock that goes from \$15 a share to \$32 a share. Your investment of \$1,500 turns into \$3,200. Assuming that you paid a \$5 commission to buy and sell the stock, your rate of return is 112.3 % and your profit is \$1,690.

It’s calculated like this:

1. Subtract the commission of \$5 from the sale proceeds of \$3,200. Write this down.

2. Add the commission of \$5 to the amount paid of \$1,500. Write this down.

3. Subtract the answer in Step 2 from the answer in Step 1 and divide that answer by the answer in Step 2. Multiply by 100.

That’s not bad. But if you bought on margin, your return would be even greater. Say your broker has a 60 percent margin requirement, meaning that you must put up 60 cents of every \$1 you invest. In this case, you’d have to put up \$900 of your own cash because that’s 60 percent of the \$1,500 purchase price. You then borrow the remaining \$600 at 10 percent interest. Your gain, thanks to margin, goes from 112.3 to 180 percent.

Here’s how your rate of return when using margin is calculated, using the previous facts as an example:

1. Subtract the commission of \$5 from the sale proceeds of \$3,200.

Write this down: \$3,195.

2. Add the commission of \$5 to the amount paid of \$1,500.

Write this down: \$1,505.

3. Multiply the amount you borrowed, \$600, by 0.10 to calculate the interest you owe.

You use 0.10 because that is 10 percent converted from percentage to decimal form. You get \$60.

4. Subtract the answer in Step 2 from the answer in Step 1.

Subtract that difference by the answer in Step 3. You get \$1,630.

5. Divide the answer in Step 4 by \$905, which is the amount of your own money you put up plus the commission you paid to buy the stock.

Multiply by 100. The answer is 180.1 percent.

If the preceding is too much math for you, do it online. Most online brokers’ sites calculate your margin requirements. If you’re interested in buying on margin, make sure that the broker has margin-tracking capabilities. This figure shows Fidelity’s Margin Calculator.

Most online brokers require investors to maintain a maintenance margin. If a stock rises, this isn’t a problem because the value of the loan becomes a smaller slice of the position. But if the stock falls in value, the shareholder’s stake shrinks. If it falls below 30 percent, the broker requires the investor to put up more cash, or the shares will be sold.

Imagine that, when you bought the previous \$15-a-share stock, you borrowed 40 percent or \$6 a share, meaning that your ownership stake is \$9 a share or 60 percent. But say the stock falls to \$7 a share. Because you borrowed \$6 a share, you own only \$1 of the \$7-a-share price. That means you own just 14 percent of the stock, violating the 30 percent margin requirement.