In mathematics and computer programming, when a number or expression is both preceded and followed by an operator such as minus or times, a rule is needed to specify which operator should be applied first; this rule is known as a precedence rule, or more informally order of operation. From the earliest use of mathematical notation^{[citation needed]}, multiplication took precedence over addition, whichever side of a number it appeared on. Thus 3 + 4 × 5 = 5 × 4 + 3 = 23. When exponents were first introduced, in the 16th and 17th centuries, exponents took precedence over both addition and multiplication, and could be placed only as a superscript to the right of their base. Thus 3 + 5 ^{2} = 28 and 3 × 5 ^{2} = 75. To change the order of operations, a vinculum (an overline or underline) was originally used. Today one uses parentheses (). Thus, if one wants to force addition to precede multiplication, one writes (3 + 4) × 5 = 35.
Contents 
The standard order of operations, or precedence, is expressed in the following chart.
In the absence of parentheses, horizontal fraction lines, a bar over a radicand, or other symbols of grouping, do all exponents and roots first. Stacked exponents must be done from the top down. After taking all exponents and roots, then do all multiplication and division. Next, do all addition and subtraction. Finally, when two operators have the same precedence, then work from the left to right.
It is helpful to treat division as multiplication by the reciprocal and subtraction as addition of the opposite. Thus 3/4 = 3 ÷ 4 = 3 • ¼ and 3 − 4 = 3 + (−4), that is, the sum of positive three and negative four.
If an expression involves multiple parentheses, then do the arithmetic inside the innermost pair of parentheses first and work outward. Root symbols have a bar (called vinculum) over the radicand which acts as a symbol of grouping: $\backslash sqrt\{1+3\}+5=\backslash sqrt4+5=2+5=7$. A horizontal fractional line also acts as a symbol of grouping: $\backslash frac\{1+2\}\{3+4\}+5=\backslash frac37+5$.
The order in which the unary operator − (usually read "minus") acts is often problematical. In written or printed mathematics, $3^2=(3^2)=9$, but in some applications and programming languages, notably the application Microsoft Office Excel and the programming language bc, unary operators have a higher priority than binary operators, that is, the unary minus (negation) has higher precedence than exponentiation, so in those languages $3^2=(3)^2=9$, . [3].
Mnemonics are often used to help learners remember the rules. One common strategy is to build an acronym from the names of the operations. For instance, in the United States, the acronym PEMDAS (for Parentheses, Exponentiation, Multiplication/Division, Addition/Subtraction) is used, sometimes expressed as the sentence "Please Excuse My Dear Aunt Sally" or one of many other variations. In other English speaking countries, Parentheses may be called Brackets, and Exponentiation may be called Indices, Powers or Orders. Also, as Multiplication and Division are of equal precedence, M and D may be interchanged in the mnemonic. (This does not mean that multiplication and division can be performed in any arbitrary order, just that it is wrong to say "M always comes before D", or "D comes before M". See below.) The same comments apply to Addition and Subtraction. Finally, "Of" can be used to refer to multiplication as in "3/4 of 8 is 6". Thus, we also have BEDMAS, BIDMAS, BIMDAS, BIODMAS, BODMAS, BOMDAS and BPODMAS.
However, all these mnemonics are misleading if the user is not aware that multiplication and division are of equal precedence, as are addition and subtraction. Using any of the above rules in the order "addition first, subtraction afterward" would give the wrong answer to
The correct answer is 9, which is best understood by thinking of the problem as the sum of positive ten, negative three, and positive two.
It is usual, wherever one needs to calculate operations of equal precedence to work from left to right. The following rules are useful:
First: perform any calculations inside parentheses (brackets)
Second: Next perform all multiplication and division, working from left to right
Third: Lastly perform all addition and subtraction, working from left to right
However, with experience, the commutative law, associative law, and distributive law allow shortcuts. For example,
is much easier when worked from right to left, where here the answer is 34.
This section may contain original research or unverified claims. Please improve the article by adding references. See the talk page for details. (February 2008) 
When restricted to using a straight text editor, parentheses (or more generally "grouping symbols") must be used generously to make up for the lack of graphics, like square root symbols. Here are some rules for doing so:
1) Whenever there is a fraction formed with a slash, put the numerator (the number on top of the fraction) in one set of parentheses, and the denominator (the number on the bottom of the fraction) in another set of parentheses. This is not required for fractions formed with underlines:
2) Whenever there is an exponent using the caret (^) symbol, put the base in one set of parentheses, and the exponent in another set of parentheses:
3) Whenever there is a trig function, put the argument of the function, typically shown in bold and/or italics, in parentheses:
4) The rule for trig functions also applies to any other function, such as square root. That is, the argument of the function should be contained in parentheses:
5) An exception to the rules requiring parentheses applies when only one character is present. While correct either way, it is more readable if parentheses around a single character are omitted:
Calculators generally require parentheses around the argument of any function. Printed or handwritten expressions sometimes omit the parentheses, provided the argument is a single character. Thus, a calculator or computer program requires:
while a printed text may have:
6) Whenever anything can be interpreted multiple ways, put the part to be done first in parentheses, to make it clear.
7) One may alternate use of the different grouping symbols (parentheses, brackets, and braces) to make expressions more readable. For example:
is more readable than:
Note that certain applications, like computer programming, will restrict one to certain grouping symbols.
In the case of a factorial in an expression, it is evaluated before exponents and roots, unless grouping symbols dictate otherwise. When new operations are defined, they are generally presumed to take precedence over other operations, unless overridden by grouping symbols.
Sometimes a dash or a heavy dot is used as a multiplication sign which has higher precedence than division. For example, $\backslash mathrm\{J/(kg\backslash \; K)\}$, $\backslash mathrm\{J/kg\backslash mbox\{\}K\}$, and $\backslash mathrm\{J/kg\backslash bullet\; K\}\backslash ;$ are all equivalent.
Different calculators follow different orders of operations. Cheaper calculators without a stack work left to right without any priority given to different operators, for example giving
while more sophisticated calculators will use a more standard priority, for example giving
The Microsoft Calculator program uses the former in its standard view and the latter in its scientific view.
The "cheap" calculator expects two operands and an operator. When the next operator is pressed, the expression is immediately evaluated and the answer becomes the left hand of the next operator. Advanced calculators allow entry of the whole expression, grouped as necessary, and only evaluates when the user uses the equals sign.
Calculators may associate exponents to the left or to the right depending on the model. For example, the expression $a\; \backslash wedge\; b\; \backslash wedge\; c$ on the TI92 and TI30XII (both Texas Instruments calculators) associates two different ways:
The TI92 associates to the right, that is
whereas, the TI30XII associates to the left, that is
An expression like 1/2x is interpreted as 1/(2x) by TI82, but as (1/2)x by TI83. While the first interpretation may be expected by some users, only the latter is in agreement with the standard rules stated above.
Many programming languages use precedence levels that conform to the order commonly used in mathematics, though some, such as APL or Smalltalk, have no operator precedence rules (in APL evaluation is strictly right to left, in Smalltalk it's strictly left to right).
The logical bitwise operators in C (and all programming languages that borrowed precedence rules from C, for example, C++, Perl and PHP) have a precedence level that the author of the language considers to be less than ideal.^{[2]} The relative precedence levels of operators found in many Cstyle languages is as follows:
1  () [] > . ::  Grouping, scope, array/member access 
2  ! ~  + * & sizeof type cast ++x x  (most) unary operations, sizeof and type casts 
3  * / %  Multiplication, division, modulo 
4  +   Addition and subtraction 
5  << >>  Bitwise shift left and right 
6  < <= > >=  Comparisons: lessthan, ... 
7  == !=  Comparisons: equal and not equal 
8  &  Bitwise AND 
9  ^  Bitwise exclusive OR 
10    Bitwise inclusive (normal) OR 
11  &&  Logical AND 
12    Logical OR 
13  ?:  Conditional expression (ternary operator) 
14  = += = *= /= %= &= = ^= <<= >>=  Assignment operators 
Examples:
order of operations
The order of operations is a mathematical and algebraic set of rules. It is used to evaluate (solve) and simplify expressions and equations. The order of operations is the order that different mathematical operations are done. The standard mathematical operations are addition (+), subtraction (−), multiplication (* or ×), division (/), brackets (which are grouping symbols, like parentheses () or []) and exponentiation (^n or ^{n}, also called orders or indices).
Mathematicians have agreed on a correct order to use operations, and it is very important that they know these rules. When people are solving a problem with more than one operation, they will need to know the correct order to solve the problem correctly. Otherwise the answer will be wrong.
Contents 
Follow all the rules in this order from left to right in the equation.
Use operations inside brackets and solve any indices. You should always solve brackets first when solving an equation.
Example:
Solve any multiplication and division in the problem.
Example:
Lastly, solve any addition or subtraction.
A good way to remember the order of operations is by remembering this phrase. The first letter of each word is also the first letter of a rule in the order.
Please: Parentheses (or brackets)
Excuse: Exponents (or indices)
My: Multiplication
Dear: Division
Aunt: Addition
Sally: Subtraction
Another good way of remembering the order of operations is the word BIDMAS, or BODMAS. The letters of the word are the same as the first letter for each rule.
B stands for Brackets
I stands for Indices, O stands for Orders
D stands for Division
M stands for Multiplication
A stands for Addition
S stands for Subtraction
