For Beginner PLC Users
For those just starting with PLC systems, I recommend first becoming familiar with combinational logic. Combinational logic will help you understand how to combine two logic states - TRUE and FALSE. With the basics of combinational logic, you can write your first PLC program.
A PLC program utilizes logic that, in mathematics, is known as Boolean algebra. In Boolean algebra, values can only be TRUE or FALSE. In PLC controllers, TRUE and FALSE are represented by 1 and 0. When programming controllers, you need to switch to "binary thinking."
In this article, I’ll use simple electrical schematics to analyze logical concepts.
Logic with Simple Examples
The simplest example involves a light bulb and two normally open switches. These two basic elements share an important characteristic: both operate in two states - the light bulb is either on or off, and the switch is either closed or open.
You can connect the light bulb and switches in several ways.
The first option is a series connection.

When two switches connect in series, the light bulb turns on only if both switches are engaged. In Boolean logic, this represents the AND function. We assume a switch is in a TRUE state when it’s closed and a FALSE state when it’s open. The same applies to the light bulb - if it’s on, its state is TRUE; if it’s off, its state is FALSE.
Combinational Logic and Six Logic Gates
Let’s go back to the AND logic function mentioned earlier. The AND function is a way of determining the output state.
AND Gate
All Boolean logic gates have inputs and outputs. The output state depends on the input states. To set an output to high (TRUE) using the AND gate, you must set all inputs to high (TRUE). In our example above, the two switches are inputs, and the light bulb is the output. In this case, the light bulb will turn on when both switches are engaged. Here’s the symbol for an AND gate:

The standard names and symbols for AND gate inputs are A and B, with Q representing the output. In its basic form this gate has two inputs and one output, though it can be expanded to accommodate more inputs but still has only one output.
The input and output states can be illustrated with a truth table, as follows:
| A | B | Q |
| False | False | False |
| True | False | False |
| False | True | False |
| True | True | True |
With this truth table, you can analyze how the output behaves based on the input states.
Below is a table to help you understand terminology in logic for various cases:
| Switch State | Boolean Algebra | PLC Program Logic |
| On | TRUE | 1 |
| Off | FALSE | 0 |
OR Gate
Parallel connections work differently from the series connection discussed previously. Here, each switch has a direct connection to the light bulb, meaning any switch can turn the light bulb on. Below is the symbol for an OR gate:

Like the AND gate, which we learned about earlier, the OR gate has two inputs and one output. The input symbols are A and B, with the output labeled Q.
The OR gate’s operation is illustrated with a truth table:
| A | B | Q |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
The OR gate output goes high (TRUE) when at least one input is high (TRUE).
The formula A + B, or A ∨ B, also represents this gate. We refer to this as logical disjunction.
NOT Gate - Logical Negation
There are six logic gates in this article that you should know: AND, OR, NOT, NAND, NOR and XOR. I will now describe the NOT gate (logical negation).

The NOT gate reverses the input state to the opposite and presents it at the output. For example, when the input is high, the output is low.
The truth table for this looks as follows:
| A | Q |
| 0 | 1 |
| 1 | 0 |
Normally Open and Normally Closed Contacts
Returning to our example with switches and the light bulb, we can enhance the functionality of our switches. Switches can operate in two different ways: they can either close or break the circuit. These two types of switches are normally open and normally closed.
NAND Gate
If we take our OR function and negate our inputs using normally closed contacts, we get a NAND function. The light turns off only when both switches are actuated (A = 1 and B = 1), because then both normally closed contacts open.
| A | B | Q |
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |

NOR Gate
Negating the inputs of the AND gate using normally closed contacts (NC) results in a NOR function.
| A | B | Q |
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |

Combined Gates
By arranging contacts in series-parallel configurations, you can implement additional logic functions such as Exclusive-OR (XOR) and Exclusive-NOR (XNOR).
Exclusive-OR Gate (XOR)

The upper branch in the electrical diagram (contact A (NC) in series with contact B (NO)) is true only when A = 0 and B = 1, which is NOT A AND B. The lower branch (contact A (NO) in series with contact B (NC)) is true only when A = 1 and B = 0, which is A AND NOT B. The two branches are connected in parallel (OR), so the output is TRUE when exactly one input is TRUE.
| A | B | Q |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Analyzing the presented electrical diagrams and logic functions, you can observe certain analogies:
- Parallel connection of NO contacts performs the OR function.
- Series connection of contacts represents the AND function.
- The normally closed contact is equivalent to the NOT (negation) gate.
Simple Programs in Ladder Logic
With a basic understanding of Boolean logic, you can proceed to programming PLC controllers, for example, using Ladder logic. This graphical language resembles an electrical diagram. Ladder language is available in programming environments such as Codesys or TIA Portal. The table below shows how each logic gate is written as a PLC ladder diagram and in Structured Text.
Logic gates in PLC: ladder diagram and Structured Text equivalents
In a programmable logic controller there are no physical logic gate chips - every logic gate is built from contacts on a rung or from a Boolean operator in text code. This short tutorial shows the PLC logic gates as a ladder logic diagram and as Structured Text, the two most common programming language choices. A NAND gate ladder diagram, a NOR gate ladder diagram and an XOR gate ladder diagram are simply combinations of normally open and normally closed contacts, exactly like the switch circuits above. The table shows all logic gates in PLC programming side by side:
| Gate | Boolean expression | PLC ladder diagram (LAD) | Structured Text (ST) |
|---|---|---|---|
| AND | Q = A · B | NO contact A in series with NO contact B | Q := A AND B; |
| OR | Q = A + B | NO contacts A and B in parallel | Q := A OR B; |
| NOT | Q = NOT A | One NC contact A | Q := NOT A; |
| NAND | Q = NOT (A · B) | NC contacts A and B in parallel | Q := NOT (A AND B); |
| NOR | Q = NOT (A + B) | NC contacts A and B in series | Q := NOT (A OR B); |
| XOR | Q = A XOR B | Two parallel branches: A NO + B NC, and A NC + B NO | Q := A XOR B; |
| XNOR | Q = NOT (A XOR B) | Two parallel branches: A NO + B NO, and A NC + B NC | Q := NOT (A XOR B); |
Complete truth table for two-input logic gates
The truth table below summarizes every two-input gate function in one place. Use it as a logic diagram cheat sheet and check your ladder logic before you download the program to the controller:
| A | B | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
NAND, NOR and XOR gate ladder diagram
This is how the three "combined" gates look as PLC ladder logic (--| |-- is a normally open contact, --|/|-- is a normally closed contact):
NAND: NOR:
|----|/|----+-----( Q )---| |----|/|-------|/|-----( Q )---|
| A | | | A B |
|----|/|----+ |
| B |
XOR:
|----| |-------|/|----+-----( Q )---|
| A B | |
|----|/|-------| |----+ |
| A B |
In Siemens TIA Portal FBD and in CODESYS you can also use ready AND, OR and XOR boxes and negate an input with a small circle, which gives the same result with less drawing.
Example: two switches controlling one light (XOR)
A classic basic logic circuit is a staircase light controlled from two places: flipping either switch changes the state of the light. In a PLC this is one rung with an XOR branch, or a single line of Structured Text, xLight := xSwitchTop XOR xSwitchBottom;. The same idea is used for two-position selector switches and for detecting that two input signals disagree, for example two sensors that should always show the same state.
Wiring tip: normally closed devices and inversion
A normally-closed contact in the program and a normally closed device in the cabinet are not the same thing. Input devices such as pushbuttons, limit switches and relay contacts are wired to the input card, and the program only sees a 1 or a 0. A stop pushbutton or an emergency limit switch is usually wired NC, so the input is 1 when the device is unactuated. If you then use a normally closed contact in the ladder logic, you invert the signal twice. Always check the input LED on the PLC input module before deciding which contact to use. Learn more about the input side in our article on sinking vs sourcing PLC inputs and outputs.
Logic gates in PLC - FAQ
Which logic gates are used in PLC programming?
Every logic gate is available: AND, OR, NOT (the inverter), NAND, NOR, XOR and XNOR. In ladder logic they are built from series and parallel contacts, and in Structured Text or Function Block Diagram they are available as Boolean operators and function boxes.
How do you make an XOR gate in ladder logic?
Use two parallel branches: in the first, a normally open contact A in series with a normally closed contact B; in the second, a normally closed contact A in series with a normally open contact B. The output coil is energized when exactly one of the inputs is TRUE. The same XOR logic gate is used in any control system that has to detect a mismatch between two signals.
Do I need to learn Boolean algebra to program PLCs?
You do not need advanced math, but the basics of Boolean algebra, truth tables and De Morgan's laws (NOT (A AND B) = NOT A OR NOT B) make PLC programming and troubleshooting much faster.
If you want to practice these gates in a real project, the Siemens TIA Portal LAD/FBD course walks you through ladder logic programming step by step, and our industrial automation basics course explains how sensors, relays and PLCs work together.
Thank you for reading! If you are interested in learning more, explore our automation courses.


