Order of Operations: The Basics

The order of operations in algebra (also called operator precedence) is a very common source of questions; I count at least 50 archived discussions explicitly about the topic (not just mentioning it in passing), in addition to the Ask Dr. Math FAQ on the subject.  I’ll devote the next few posts to looking at various aspects of it. Here, we’ll look at how we state the essentials for beginners. In a later post we’ll consider why it is what it is, and not something else.

PEMDAS

First, here is a very basic question from 1998:

Order Of Operations in Four Steps

I need help figuring out what operation to do first. I have heard of Pemadas but I do not know what it means. Can you help?

Doctor Schwenoha answered:

Not pemadas, but PEMDAS. We have used this acronym for the order of operations for a long time to help remember the key words:  

Parentheses, Exponents, Multiplication, Division, Addition, and Subtraction.  

There is a tendency to just remember the words and not remember some groupings that occur, though. I have lately been teaching the order of operations as a list of 4 things rather than using pemdas.

1. Parentheses - do everything in parentheses first.  Go to the innermost parentheses first if there is more than one set of parentheses in the problem. If there is more than one set but they are isolated from each other, then do them independently. 

If you are dealing with a fraction you should treat the top as if it were in parentheses and the bottom as if it were in parentheses even if the parentheses weren't written in the original state.  That's because the fraction bar means division and we'll get to that after we take care of any parentheses.

In addition to PEMDAS, there are several other versions used in various English-speaking countries, such as BODMAS, BIDMAS, BEDMAS, and so on. I’m not sure how far back any of them go, but I imagine they started in the 20th century, and probably among teachers.

This first level of precedence essentially tells how to explicitly state the order you intend, and how to interpret it. Parentheses, “(…)”, and fraction bars, “\(\frac{\cdots}{\cdots}\)“, are two “grouping symbols” that tell you “do this part first”. Other symbols, such as brackets, “[…]” and braces, “{…}”, are equivalent to parentheses, and just let us match them up more easily.

The comments about “innermost parentheses” and “isolated parentheses” refer, respectively, to forms like \((A\cdots(B\cdots)\cdots)\) and \((A\cdots)\cdots(B\cdots)\); in the first case you must evaluate B before you can do A, while in the second you can evaluate A and B in any order, as long as you do both before anything outside of them.

One thing left out here is that the rest of the rules still apply within parentheses; you can’t “do” parentheses themselves, so you can’t finish them before doing any operations. For example, in $$2(3x-4y)-5$$ we have to apply the rule that the multiplications, \(3x\) and \(4y\), must be done before the subtraction, in order to evaluate what is in the parentheses.

2. Exponents - After clearing up any parentheses that you can, you should next go to any exponents. Remember that the exponent goes with the thing it is closest to. If it had been closest to a parenthesis sign then you have already cleared up the parentheses before worrying about the exponent.

As usually written, an exponent is also set apart by being raised, so it acts as a sort of grouping symbol. You must evaluate the exponent as a number before you can apply it. In typing, we use the caret, “^”, to indicate an exponent; since that notation does not implicitly show where the exponent ends, it is necessary to use parentheses when there is more than just a number or variable, as in “2x^(n+1)”.

But that is not the main point of this step. The important thing here (and the part that students easily get wrong) is that the base (the number to be raised to a power) is just whatever the exponent is directly attached to. For example, $$2x^{n+1}$$ is evaluated by first evaluating \(n+1\), then raising the base \(x\) to that power, and only then multiplying by 2.

3. Multiplication AND division as you come to it going from left to right - these two operations need to be seen as a team rather than as separate entities. Using PEMDAS to remember the words is fine, but you have to see the "MD" as a connected word.

So any consecutive groups of multiplications and divisions are done before additions or subtractions, each group by itself: $$2\div 3 \times 6\ + \ 2\times 3 \div 6$$ means that you do the division and multiplication in the first group, $$2\div 3 \times 6 = \frac{2}{3}\times 6 = 4$$ and the multiplication and division in the second group, $$2\times 3 \div 6 = 6\div 6 = 1$$ before adding them: $$4 + 1 = 5$$

4. Addition AND subtraction as you come to it going from left to right - again, see the "as" as a connected word.

Once we’ve reached this point, we just have a string of additions and subtractions, and we do them all in order as written. The order of operations tells us to see any expression as a group of terms being added and subtracted (unless parentheses modify that).

So, there is the order of operations. The only thing that makes this the correct order is that mathematicians all over the world agreed a long time ago to do it this way. So no matter if you speak German and another person speaks French, you both speak MATHEMATICS and can communicate with each other.

Yes, this is a convention (that is, an agreement among its users) that is “correct” only because it has been agreed to; but that doesn’t mean it is arbitrary. As I mentioned, we will come to the likely reasons for it in a later post.

Applying the rules

A set of rules is one thing; but how do you actually use them to evaluate an expression? That’s the subject of this 2003 question:

Parentheses from the Inside Out

I don't understand evaluating expressions.

The things that I find most difficult are following PEMDAS and multiplying the fractions by the whole numbers without using a calculator.

Here's a problem from my homework. 

2b divided by a+2 to the second power. b = 1.5, a = 3 
  1. 2(1.5)divided by 3 + 2 to the second power.
  2. 3.5 divided by 3 + 2 to the 2 power
  3. 1.5+4
  4. 5.5 is this right?

Kaila has to evaluate an expression with variables, given specified values of those variables. The specific expression here appears to be $$2b\div a + 2^2,$$ all in a line. But it might have been written with a fraction bar and/or parentheses, as $$\frac{2b}{(a + 2)^2}$$ or maybe $$\frac{2b}{a}+ 2^2.$$ Because it is not written exactly as given (and plain text email made that difficult), it is hard to be sure.

Parentheses

Doctor Ian chose to start off with another (slightly more complicated) example to explain the whole process, bypassing these uncertainties. He starts with Parentheses, which as we saw above let us explicitly say what to look at first. Note that in typing, we use “*” for “×” and “/” for “÷”. We have to start by looking at the contents of the outermost parentheses:

Let's look at an expression like 

  2 + 3 * (4 - 5 * (6 / 3)) - 4

The parentheses are like an envelope that we have to open to find out what's inside.  The first parentheses we run into are

  (4 - 5 * (6 / 3))

so we forget about everything else while we work this out:

   4 - 5 * (6 / 3)

He is ignoring everything outside this outermost pair of parentheses for now, as if spreading out the mail and finding one big package to open. But that package contains another package:

Oops!  We have more parentheses.  So let's forget about everything else until we work out

  6 / 3

Okay, there's just one operation, so we do it: 6/3 = 2, so we can go back and replace the parentheses (and everything inside) with the result:

   4 - 5 * 2

What we’ve done to far is to dig down to the innermost parentheses, and do what was inside.

If there was a more complicated expression inside than \(6\div 3\), we would have had to follow all the other rules even in there. Those rules tell us to do multiplications and divisions first:

Now we have no parentheses, so we look for multiplications and divisions.  There is just one multiplication, so we do it:

  4 - 10

And now we just have a subtraction, so we do that:

  -6

So now -6 replaces what was in the original parentheses:

  2 + 3 * -6 - 4

This represents the entire expression, having replaced the parentheses (that big package) with its value.

Again, we have just one multiplication, so we do it:

  2 + -18 - 4

And now we have additions and subtractions, so we do them left to right:

  2 + -18 - 4

   -16 - 4

   -20

And that's our result.

That’s the basic process.

Left to right

But we also have to be aware of what not to do:

Note that doing operations right to left (instead of left to right) can give you the wrong answer.  For example, consider

  72 / 6 / 3

Doing the operations right to left would give us

  72 / 2

which is 36; while doing them left to right gives us

  12 / 3

which is 4.  Also, if we do 

  10 - 5 - 3

from right to left, we get

  10 - 2

which is 8; but if we do it from left to right, we get

  5 - 3

which is 2.

How did she do?

After giving another example, where he inserts parentheses to show the order, he gets back to the original question and the ambiguity due to the use of words rather than symbols:

Note that the phrase

  2b divided by a+2 to the second power

could be interpreted in more than one way.  It might mean

                                                 2b   2
  (2b divided by a+2) to the second power -->  ( --- )
                                                 a+2
or
                                                    2b   
  2b divided by ((a+2) to the second power) -->  -------- 
                                                       2
                                                  (a+2)
or
                                                    2b   
  2b divided by (a+(2 to the second power)) -->  ---------- 
                                                        2
                                                  a + (2 )

But, if it was copied as closely as possible, then there is only one literal interpretation, \(2b\div a + 2^2\). He adds parentheses, step by step, to show the required order:

And in fact, with no parentheses, following the PEMDAS order, the phrase would be interpreted this way:

  2b divided by a+(2 to the second power)       E

  (2b) divided by a+(2 to the second power)     M or D

  ((2b) divided by a)+(2 to the second power)   M or D

that is, 

    2b      2
   ---- + (2 )
     a

So if they really wrote it in symbols, as 

            2
  2b ÷ a + 2

instead of using words, then this last interpretation is the conventional one. Note that a fraction bar acts like two pairs of parentheses with a division sign in between:

  blah blab blah
  -------------- = (blah blah blah) / (yadda yadda)
   yadda yadda

How about Kaila’s work?

> 2b divided by a+2 to the second power. b = 1.5, a = 3 
>   1. 2(1.5)divided by 3 + 2 to the second power.
>   2. 3.5 divided by 3 +2 to the 2 power
>   3. 1.5+4
>   4. 5.5 is this right?

Let's follow the PEMDAS order, and see if we get the same thing. There is an exponent, so we want to evaluate that first. Then we want to do multiplications and divisions, from left to right. Finally, we want to do additions and subtractions from left to right. 

    2 * 1.5 / 3 + 2^2
                  ---           Exponent

    2 * 1.5 / 3 + 4
    -------                     Multiplication           

    3 / 3 + 4
    -------                     Division

    1 + 4
    -----                       Addition


    5                           Result

So there’s the correct value.

Why is this different from your answer? For one thing, it looks as if you multiplied 2 by 1.5 and got 3.5, instead of 3. That may have been a slip, or it might indicate that you need to work on your multiplication skills.

I think she may have just accidentally added. I don’t know about the \(3.5\div 3 = 1.5\); but she correctly did the exponent first.

To check, I'd probably think about money. If two of us have $1.50 each, how much money do we have? Two dollars and two half dollars is three dollars, so 2 * 1.50 must be 3. But everyone thinks about math a little differently from everyone else, so you have to find out what works for you. 

Anyway, I hope this has helped you see why we have these conventions, and what can happen if you do operations out of order. Write back if you'd like to talk more about this, or anything else.

Getting more complicated

The next question, from 2007, gave us a chance to see how to approach a really big expression. Here we have multiple grouping symbols, and numerous decisions to be made (though there are no exponents):

Evaluating Parentheses, Brackets, Braces and Grouping Symbols

(18/2){[(9 x 9 - 1)/ 2] - [5 x 20 - (7 x 9 - 2)]}

Parentheses, brackets and braces are very confusing to me.  For instance, the mathematical sentence above displays more brackets, parentheses and braces than numbers.

According to the mathematical rules in place today, what am I supposed to know in order to see this problem and quickly know where to start and where to follow next in order to ensure that I will always get to the right answer?

Even though I know that I am supposed to start with the innermost parentheses and then follow with the [ ], and then the { }, I still feel very uncomfortable with these figures mixed with the numbers.

(18/2){[(9 x 9 - 1)/ 2]-[5 x 20 - (7 x 9 - 2)]}

Here, I start by: 9 x 9 = 81 - 1 = 80.  But then what do I do?  Keep going through the ( ) and divide 80 by 2 = 40?  If that's the right course of action, then I'd follow with: 7 x 9 = 63 - 2 = 61, then I would come back and do: 5 x 20 = 100 - 61 = 39.  And then, last, I'd divide 18 by 2 = 9.  Then, 40 - 39 = 1; then 9 x 1 = 9?

Obviously, I am going more by instincts than by logic.  What do I need to know in order to laugh about problems like the one above instead of worrying about them?

One possible misunderstanding here is a belief that grouping symbols must be used in a certain order; but Nelson is probably just describing the order in which they appear (from the inside out) in this example. The reality is that, although this order, {[(…)]}, is common in practice, there is no rule distinguishing the symbols. They are used only to help finding matching pairs.

I responded:

The first thing to do is to start with something not quite so complicated, so you can get used to the ideas first.  But let's go ahead with this one, to check your work.

In similar cases with younger students who seemed to be jumping in the deep end, I’ve dropped their problem and just showed one they are ready for. But Nelson seemed ready to tangle with monsters, so I took it on:

Here's one way I write these to demonstrate how to think it through:

  (18/2){[(9 x 9 - 1)/ 2]-[5 x 20 - (7 x 9 - 2)]}
  \____/  \_________/               \_________/
     9  {[    80     / 2]-[5 x 20 -     61     ]}
         \______________/ \____________________/
     9  {       40       -           39         }
        \_______________________________________/
     9 *                  1
     \____________________/
                9

So you're correct, and your work was fine.  The only thing I did differently was to evaluate 18/2 earlier, because nothing stood in its way; I could have waited as you did.

I did something like what Doctor Ian did, but more compactly, replacing one chunk at a time with its value. Notice that I did more than one thing on a line, which will deal with Nelson’s main question.

Now we can break it down and think about why I did what I did:

What parentheses do is to contain a subexpression that has to be fully evaluated before it can be used in any containing expression.  That's why you work from the inside out: you can't use what's inside until you evaluate it all, so you might as well start there.  But if you forgot to, you'd still have a reminder.  Here's an example:

  2[(3 + 7)(3 - 2) - 3(2 + 2)]

What if I didn’t know to start on the “inside”, but just knew the rules?

If I didn't bother with the inside-out "rule", I  might just start trying to evaluate at the left (paying attention to the order of operations, of course): 2 times ... what?  Well, the second number in that multiplication is the whole thing inside [...], so I have to put it on hold until I do that.  So I focus on

  (3 + 7)(3 - 2) - 3(2 + 2)

Now I start that.  The first piece is (3 + 7), so I evaluate that whole thing and get 10.  Now I have to multiply it by (3 - 2), so I stop and evaluate that, which gives 1.  Now I can multiply 10 by 1 and get 10.  So I keep going; I have to subtract something from that, but since the next bit is a product, I have to do that first.  I'll have 3 times the next parenthesis; that's 3 times 4, so I have 12.  The subtraction I put off is 10 - 12 = -2.

Now, this is what the whole [...] is, so I go back and do that last multiplication:

  2*(-2) = -4

This involved a lot of thinking, setting something aside and making sure to come back to it later. It’s not what I’m going to recommend doing, but an exercise to see how it all works.

That was pretty ugly, wasn't it?  That's how a computer would evaluate it (more or less); it just keeps putting something on hold and coming back to it when it's ready, because it has a really good memory and won't forget to do it!  We don't recommend this method for humans, but it can be done.  Here's how I'd usually do it:

  2[(3 + 7)(3 - 2) - 3(2 + 2)]
    \_____/\_____/    \_____/
  2[   10  *  1    - 3*  4   ]
       \______/      \___/
  2[      10       -   12    ]
   \_________________________/
  2*            -2
  \______________/
        -4

Again, I just evaluated ANY parenthesized subexpression that didn't have anything standing in its way (that is, ALL the innermost ones); then I went through it again evaluating everything that was left the same way.

Notice what Doctor Schwenoha described as independently evaluating isolated parts. It doesn’t matter in what order I do things that don’t affect one another.

Even that fairly compact way of writing it is something I do largely when I’m trying to show someone what is going on inside my mind:

In reality, on paper, my work might look like this, just jotting down the value of each parenthesis as I came to it, but doing most of the work in my head:

  2[(3 + 7)(3 - 2) - 3(2 + 2)] = 2[10 - 12] = -4
     10     1          4

But it is important to write something down so I can see what needs to be done, and avoid making mistakes. I’m not a computer!

My point is that inside-out is not a magic formula; it's just a natural result of what parentheses do.  Wherever you find a parenthesis, you make sure it gets evaluated before you use that particular result in any further operations.  So, for example, that (18/2) in your example could be done at any time, because it wasn't needed until the end anyway.

I suspect your "instinct" is to do exactly this, and it fits with the logic perfectly (when you let it operate).

For another version of these ideas, see

Order of Operations: Parentheses as Packages

Next time, we’ll look at details that are often missed.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.