Free · No sign-up · Works offline

Infix to Postfix Converter

Type any infix expression and get the postfix form instantly — along with the complete stack trace showing exactly which operator was pushed, popped and why.

Use letters or numbers as operands and the operators plus, minus, times, divide, modulo and caret for power. Brackets are supported.

Try:

An infix to postfix converter turns an ordinary arithmetic expression into Reverse Polish Notation (RPN) by reading the expression once from left to right and holding each operator on a stack until its position is fixed. Enter A + B * C and the converter returns A B C * +.

An infix to postfix converter gives three benefits: it removes every bracket from the expression, it removes operator precedence from the evaluation step, and it produces a form a machine evaluates in a single pass with one stack. Compilers, command editors and calculators all run the conversion before evaluating anything.

An infix to postfix converter has four parts: a tokenizer that splits the input string into operands and operators, a precedence table, an operator stack, and an output queue.

How to use this infix to postfix converter

Use this infix to postfix converter step by step: type an expression, read the postfix result, then check the trace underneath. Nothing is uploaded — the whole conversion runs in your browser as you type.

  1. Type the infix expression. Operands can be single letters (A), whole words (rate) or numbers (3.5). Operators are +, -, *, /, % and ^. Round, square and curly brackets all work.
  2. Read the postfix result. It updates as you type — no need to press anything. Use the copy button to take it into your assignment or code.
  3. Check the trace. The table underneath shows the stack and the output after every single token, with a sentence explaining the decision. That is the part your lecturer wants to see, not just the final answer.

What is infix notation?

Infix notation is the ordinary way of writing arithmetic: the operator sits between its two operands, as in A + B. It reads naturally to humans, but it is ambiguous on its own — A + B * C only means "multiply first" because we all agree on precedence rules, and brackets exist purely to override those rules.

What is postfix notation?

Postfix notation — also called Reverse Polish Notation (RPN) — puts the operator after its operands: A B +. Once an expression is in postfix there are no brackets and no precedence rules left to apply. The order of the symbols alone fixes the order of evaluation, which is why compilers, calculators and stack-based virtual machines convert to postfix before evaluating anything.

Where the operator sits in infix, prefix and postfix notationNOTATIONHOW A + B IS WRITTENINFIXA+BThe operator sits between its two operands.PREFIX+ABThe operator comes first. Also called Polish notation.POSTFIXAB+The operator comes last. Also called Reverse Polish.
The three notations differ in one thing only: where the operator sits relative to its operands. Postfix needs no brackets because that position alone fixes the order of evaluation.
The same expression in all three notations
Infix Postfix (RPN) Prefix (Polish)
A + BA B ++ A B
A + B * CA B C * ++ A * B C
(A + B) * CA B + C ** + A B C
A * B + C / DA B * C D / ++ * A B / C D

How the conversion works

The converter runs Dijkstra's shunting-yard algorithm. It reads the infix expression left to right, sends operands straight to the output, and parks operators on a stack until it is certain where they belong. An operator waits on the stack while everything above it binds more tightly; the moment a weaker operator or a closing bracket arrives, it is popped to the output.

That single rule is what turns A + B * C into A B C * +: when * arrives, it outranks the + already on the stack, so + stays put and waits its turn.

An expression tree read three ways gives infix, prefix and postfixEXPRESSION TREE FOR A + B * C+A*BCIN-ORDER → INFIXA + B * CPRE-ORDER → PREFIX+ A * B CPOST-ORDER → POSTFIXA B C * +
Every expression is really a tree. Read it left-to-right through the middle and you get infix; read each node before its children and you get prefix; read each node after its children and you get postfix. The converter is just producing this post-order reading without ever building the tree.
Going deeper

The full rule set, pseudocode and a hand-worked dry run live on the infix to postfix conversion algorithm page. If you specifically need to show the stack in your answer, use the stack walkthrough.

Operator precedence and associativity

Precedence decides which operator wins when two compete; associativity breaks the tie when they are equal. These are the values this converter uses, and they match the convention used in almost every data structures course.

Precedence used for infix to postfix conversion — higher binds tighter
Operator Meaning Precedence Associativity
^Exponentiation3 (highest)Right to left
* / %Multiply, divide, modulo2Left to right
+ -Add, subtract1 (lowest)Left to right
( )GroupingPushed as a marker, never output

Right associativity is the reason a ^ b ^ c becomes a b c ^ ^ and not a b ^ c ^ — it is read as a ^ (b ^ c). Every other operator here associates left to right.

Modulus sits with multiplication, not exponentiation

Several converter sites group % with ^ at the same precedence level. That grouping is wrong. Modulus shares its level with * and / in C, Java, Python and every standard implementation, so a % b ^ c converts to a b c ^ %. The incorrect grouping produces a b % c ^, which is a different expression. Paste either into the converter above to check.

Infix to postfix examples with answers

Two worked conversions, both numeric so the value gives a free check on the answer. Every row below comes from the converter above.

Example #1: 6*4+2^5-3

6 * 4 + 2 ^ 5 - 3 converts to 6 4 * 2 5 ^ + 3 - and evaluates to 53. The conversion takes 10 steps.

Step by step conversion of 6*4+2^5-3
#TokenActionStackOutput
16Operand — send it straight to the output.empty6
2*The stack is empty — push "*".*6
34Operand — send it straight to the output.*6 4
4+Pop * to the output (precedence at least "+"), then push "+".+6 4 *
52Operand — send it straight to the output.+6 4 * 2
6^"^" binds tighter than "+" on top — push "^".+ ^6 4 * 2
75Operand — send it straight to the output.+ ^6 4 * 2 5
8-Pop ^, + to the output (precedence at least "-"), then push "-".-6 4 * 2 5 ^ +
93Operand — send it straight to the output.-6 4 * 2 5 ^ + 3
10endEnd of input — pop the remaining operator - to the output.empty6 4 * 2 5 ^ + 3 -

Example #2: 4*((2+6)/3)-2^2^3

4 * ((2 + 6) / 3) - 2 ^ 2 ^ 3 converts to 4 2 6 + 3 / * 2 2 3 ^ ^ - and evaluates to -245.333. The conversion takes 18 steps.

The two ^ operators are the point of this example. Exponentiation associates right to left, so the second ^ does not pop the first one, and the output ends 2 2 3 ^ ^ rather than 2 2 ^ 3 ^.

Step by step conversion of 4*((2+6)/3)-2^2^3
#TokenActionStackOutput
14Operand — send it straight to the output.empty4
2*The stack is empty — push "*".*4
3(Push "(" onto the stack as a marker.* (4
4(Push "(" onto the stack as a marker.* ( (4
52Operand — send it straight to the output.* ( (4 2
6+The top of the stack is "(" — push "+".* ( ( +4 2
76Operand — send it straight to the output.* ( ( +4 2 6
8)Pop + to the output, then discard the matching "(".* (4 2 6 +
9/The top of the stack is "(" — push "/".* ( /4 2 6 +
103Operand — send it straight to the output.* ( /4 2 6 + 3
11)Pop / to the output, then discard the matching "(".*4 2 6 + 3 /
12-Pop * to the output (precedence at least "-"), then push "-".-4 2 6 + 3 / *
132Operand — send it straight to the output.-4 2 6 + 3 / * 2
14^"^" binds tighter than "-" on top — push "^".- ^4 2 6 + 3 / * 2
152Operand — send it straight to the output.- ^4 2 6 + 3 / * 2 2
16^"^" is right-associative, so an equal-precedence "^" stays put — push "^".- ^ ^4 2 6 + 3 / * 2 2
173Operand — send it straight to the output.- ^ ^4 2 6 + 3 / * 2 2 3
18endEnd of input — pop the remaining operators ^, ^, - to the output.empty4 2 6 + 3 / * 2 2 3 ^ ^ -

Quick reference table

Common textbook expressions and their answers. Click any infix to postfix converter example with solution below to load it into the tool above and see the full stack trace, not just the final line.

Infix to postfix conversion examples with answers
Infix expression Postfix answer Why
A + BA B +The simplest case
A + B * CA B C * +* binds tighter than +
(A + B) * CA B + C *Brackets force the addition first
A * B + C * DA B * C D * +Both products resolve before the sum
A - B - CA B - C -Left associative, so it is (A - B) - C
A ^ B ^ CA B C ^ ^Right associative, so it is A ^ (B ^ C)
A + B * C - D / EA B C * + D E / -Two products, then the subtraction
(A + B) * (C - D)A B + C D - *Each bracket flushes independently
A + B * C - (D / E ^ F) * GA B C * + D E F ^ / G * -Precedence and brackets combined

Using it as an infix to postfix calculator

If every operand is a number, the tool goes one step further and evaluates the postfix expression for you — the Evaluates to row appears automatically. Try 3 + 4 * 2 / (1 - 5) ^ 2: the postfix form is 3 4 2 * 1 5 - 2 ^ / + and the value is 3.5. Mixed expressions with variables still convert; they simply have nothing to evaluate.

Applications

Infix to postfix conversion has five applications.

  • Compilers convert expressions to postfix before generating code.
  • Calculators convert once, then evaluate the postfix form with a value stack.
  • Stack machines run postfix directly — the Java Virtual Machine and CPython both execute stack bytecode.
  • Command editors parse arithmetic arguments through the same conversion.
  • Data structures courses use the conversion as the first real application of a stack.

Humans read infix easily and pick out the order of operators by eye. A machine cannot separate operators and parentheses that cheaply, which is why postfix conversion comes first.

Frequently asked questions

How do you convert infix to postfix?

Scan the infix expression from left to right. Send every operand directly to the output. Push ( onto a stack. When you hit ), pop operators to the output until the matching ( appears and discard the pair. When you hit an operator, first pop any stacked operator with greater or equal precedence to the output, then push the new one. At the end, pop whatever remains on the stack.

Why convert an infix expression to postfix at all?

Postfix removes brackets and precedence entirely, so a machine can evaluate it with one pass and one stack — push operands, and on each operator pop two values and push the result. Compilers and calculators do this because parsing infix directly on every evaluation would be far slower and much harder to implement.

Is postfix notation the same as Reverse Polish Notation?

Yes. Postfix and Reverse Polish Notation (RPN) are two names for the same thing: the operator written after its operands. Prefix notation — the operator written first — is called Polish notation.

What happens to the brackets during conversion?

Brackets never appear in the output. A ( is pushed purely as a marker so the algorithm knows where to stop popping; when the matching ) arrives, both are thrown away once the operators between them have been flushed to the output. A valid postfix expression contains no brackets at all.

Does this converter handle multi-character operands and decimals?

Yes. Variable names such as rate or x1 and numbers such as 3.5 or 250 are treated as single operands. Many classroom implementations only handle one character per operand, which is why 12 + 3 breaks in them but works here.

What is the time complexity of the conversion?

O(n) time and O(n) space for an expression of n tokens. Each token is read once and each operator is pushed once and popped once, so the total work stays linear no matter how deeply nested the brackets are.

Why does a ^ b ^ c give a b c ^ ^ instead of a b ^ c ^?

Exponentiation is right associative, so a ^ b ^ c means a ^ (b ^ c). The rule inside the algorithm is that an incoming right-associative operator only pops operators of strictly greater precedence, so the first ^ stays on the stack when the second one arrives.

Can I share a converted expression?

Yes — the address bar updates as you type, so copying the URL gives you a link that reopens the page with the same expression already converted.

Can you convert infix to postfix without using a stack?

Yes. Build an expression tree from the infix expression and read the tree in post-order, or use recursive descent parsing. Both methods still use a stack indirectly through the call stack, and both take more code than the single-pass stack method.

What is the difference between infix, postfix and prefix?

The operator position differs. Infix writes the operator between its operands (A + B), postfix writes the operator after them (A B +), and prefix writes the operator before them (+ A B). Postfix and prefix need no parentheses; infix needs both parentheses and precedence rules.

Which infix to postfix question appears most often in exams?

Expressions of the form A - B - C and A / B / C. Pushing on equal precedence instead of popping gives A B C - -, which means A - (B - C). The correct answer is A B - C -.