Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 38 ยท Expressions and Order of Operations

Order of Operations

Master the order of operations with PEMDAS and BODMAS: parentheses, exponents, multiplication and division, then addition and subtraction, with examples.

What is 2 + 3 ร— 4? If you add first, you get 5 ร— 4 = 20. If you multiply first, you get 2 + 12 = 14. Both cannot be right, so mathematicians agreed on a single set of rules, the order of operations. Everyone who follows it gets the same answer, whether they are in Lagos, Lima or Lahore, and whether they use paper or a computer.

The rules

Work through an expression in this order:

  1. Parentheses (and other grouping symbols): do what is inside first.
  2. Exponents (powers and roots): next. (You will study them in the next lessons.)
  3. Multiplication and division: from left to right, as they appear.
  4. Addition and subtraction: from left to right, as they appear.

In the United States this is remembered as PEMDAS; in the UK and many other countries as BODMAS (Brackets, Orders, Division and Multiplication, Addition and Subtraction). They describe the same rules.

flowchart TD
    A["1. Parentheses"] --> B["2. Exponents"]
    B --> C["3. Multiplication and division<br/>(left to right)"]
    C --> D["4. Addition and subtraction<br/>(left to right)"]

Multiplication and division share one level; so do addition and subtraction.

The letters can mislead you. Multiplication does not always come before division, and addition does not always come before subtraction. Each pair is one level, done left to right.

Worked examples

Example 1: 2 + 3 ร— 4. No parentheses or exponents. Multiplication first: 3 ร— 4 = 12. Then 2 + 12 = 14.

Example 2: (2 + 3) ร— 4. Parentheses first: 2 + 3 = 5. Then 5 ร— 4 = 20. The parentheses changed the answer.

Example 3: 24 รท 4 ร— 3. Same level, so go left to right: 24 รท 4 = 6, then 6 ร— 3 = 18. (Doing 4 ร— 3 first would wrongly give 2.)

Example 4: 20 โˆ’ 8 + 3. Same level, left to right: 20 โˆ’ 8 = 12, then 12 + 3 = 15. (Not 20 โˆ’ 11 = 9.)

Example 5: 5 + 2 ร— (9 โˆ’ 3) รท 4.

  • Parentheses: 9 โˆ’ 3 = 6, giving 5 + 2 ร— 6 รท 4.
  • Multiplication/division left to right: 2 ร— 6 = 12, then 12 รท 4 = 3.
  • Addition: 5 + 3 = 8.

Programming languages follow the same order, which makes them handy checkers. In Python, ** means exponent.

Python Check the order of operations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each result matches the hand calculations above (division in Python prints decimals such as 3.0).

Nested parentheses

When parentheses sit inside other parentheses, start with the innermost pair and work outward. Brackets [ ] and braces { } do the same job and just make nesting easier to read.

3 ร— [4 + (10 โˆ’ 6) รท 2]

  • Innermost: 10 โˆ’ 6 = 4, so 3 ร— [4 + 4 รท 2].
  • Inside the bracket, division first: 4 รท 2 = 2, so 3 ร— [4 + 2].
  • Bracket: 4 + 2 = 6, so 3 ร— 6 = 18.

The fraction bar is a grouping symbol

In (8 + 4) / (2 + 1) and in the stacked form with a bar, the top and bottom are each evaluated first: 12 / 3 = 4. When you type a fraction on a computer, you must add parentheses yourself; otherwise 8 + 4 / 2 + 1 means 8 + 2 + 1 = 11.

A step-by-step evaluator

The program below shows every stage of a calculation, so you can compare it to your own working. It is a small helper that evaluates in the usual order and then prints the pieces you ask about.

Python Compare a calculation with and without parentheses

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Look at the pair 36 / 6 / 2 and 36 / (6 / 2): the left-to-right rule gives 3.0, but the parentheses give 6.0.

Common mistakes

  • Adding before multiplying: 2 + 3 ร— 4 is 14, not 20.
  • Forgetting left to right for equal-level operations.
  • Dropping a negative sign. (More on negatives in chapter 3.)
  • Ignoring that parentheses force an order.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Evaluate 6 + 4 ร— 5.

    Multiply first: 4 ร— 5 = 20, then add: 6 + 20 = 26.
  2. 2. Evaluate 48 รท 6 ร— 2.

    Division and multiplication are on the same level, so work left to right: 48 รท 6 = 8, then 8 ร— 2 = 16.
  3. 3. Evaluate 3 ร— (7 โˆ’ 2) + 4.

    Parentheses: 7 โˆ’ 2 = 5. Multiply: 3 ร— 5 = 15. Add: 15 + 4 = 19.
  4. 4. Evaluate 18 โˆ’ 6 + 2.

    Same level, left to right: 18 โˆ’ 6 = 12, then 12 + 2 = 14. Careful: the answer is 14, not 10.

Summary

  • Order: parentheses, exponents, multiplication and division (left to right), addition and subtraction (left to right).
  • PEMDAS and BODMAS are two names for the same rules.
  • Multiplication and division share a level, and so do addition and subtraction.
  • Evaluate the innermost parentheses first, and treat a fraction bar as grouping.

Next: Exponents and Powers