Ladder logic: rungs, contacts, coils, timers
Short answer: Ladder logic, called ladder diagram (LD) in IEC 61131-3, is the PLC programming language that draws control logic as rungs between two vertical rails. Contacts on the left of each rung test bits, a coil on the right sets a bit, contacts in series act as AND and contacts in parallel act as OR, and the PLC solves the rungs from top to bottom once every scan. Timers and counters are standard function blocks such as TON, TOF and CTU placed on a rung.
Ladder logic explained: rails and rungs, normally open and closed contacts, coils, seal-in circuits, TON, TOF and CTU blocks, and three worked examples.
This article covers what ladder logic is, rails and rungs, normally open and normally closed contacts, coils, the seal-in circuit, TON, TOF and CTU function blocks, how the scan evaluates rungs, three worked examples, and when structured text is the better choice. It does not cover any one vendor's instruction set in full, safety PLC programming, or motion control.
Ladder logic is a graphical PLC programming language, called ladder diagram (LD) in the IEC 61131-3 standard, that draws control logic as rungs of contacts and coils between two vertical power rails. It was drawn to look like the relay wiring diagrams it replaced: the Siemens S7-1200 system manual describes its elements as those of a circuit diagram, normally open and normally closed contacts and coils, linked to form networks. This article covers the parts of a ladder program, how a PLC evaluates it, the standard timers and counters, three worked examples, and when structured text does the job better.
Rails and rungs
A ladder program has two vertical lines, the left rail and the right rail, and a series of horizontal rungs between them. Think of the left rail as the supply: if there is an unbroken path through the elements of a rung from the left rail to the coil, the rung has power flow and the coil is on. Siemens’ STEP 7 calls each rung a network, and its manual states that a branch may not create power flow in the reverse direction, so power always reads as moving from left to right.
Each rung reads like a sentence. The contacts on the left are the conditions, and the coil or function block on the right is the result. The S7-1200 manual requires every network to end in a coil or a box instruction. A rung can split into parallel branches and join again, which is how one rung expresses “either this or that”.
Contacts and coils
A contact tests one bit. That bit can be a physical input, an output, or an internal memory bit. The two basic kinds are named after relay contacts:
| Element | Symbol | Passes power when | Typical use |
|---|---|---|---|
| Normally open (NO) contact | --| |-- | its bit is 1 | Start button pressed, sensor sees a part |
| Normally closed (NC) contact | --|/|-- | its bit is 0 | Stop condition not present, fault not active |
| Coil | --( )-- | sets its bit to 1 while the rung has power flow, 0 when it does not | Drive an output or an internal bit |
| Set coil | --(S)-- | sets its bit to 1 when the rung is true, leaves it alone otherwise | Latch a fault until it is reset |
| Reset coil | --(R)-- | sets its bit to 0 when the rung is true, leaves it alone otherwise | Clear a latched fault |
These definitions follow the S7-1200 system manual, which also states the two rules that make ladder work as logic: contacts connected in series create AND logic, and contacts connected in parallel create OR logic. A normally closed contact gives you NOT.
The names describe how the contact reads a bit in the program. They say nothing about the switch out on the machine. A stop button can be wired either way, and the programmer picks the contact type that gives the right result for that wiring. When reading someone else’s program, check the electrical drawings before assuming what a contact means.
A plain coil follows its rung every scan: on while the rung is true, off when it is false. Set and reset coils remember. Use one plain coil per bit; writing the same bit from two rungs means the lower rung wins and the upper one appears to do nothing.
How the scan evaluates the rungs
A PLC does not run a ladder program the way current flows through a relay panel, where every rung is live at once. It runs it as a program, inside the scan cycle described in the PLC article: read all inputs into memory, solve the program, write all outputs, repeat. The S7-1200 manual describes the program step as executing the user program “from the first instruction through the end instruction”, with inputs copied into the process image just before.
Three consequences follow, and most beginner surprises come from them:
- Every rung sees the same inputs. The inputs are frozen in the process image for the whole scan, so a button that changes halfway through a scan is seen by all rungs on the next one.
- Order matters for internal bits. Rungs are solved from top to bottom. If rung 5 sets a bit that rung 2 reads, rung 2 sees the new value on the next scan, one scan late.
- Outputs change at the end. A coil’s bit can change several times during a scan, but the physical output is written once, after the last rung.
Timers behave the same way. The S7-1200 manual explains that an IEC timer is updated only when its instruction runs or when another instruction reads its Q or elapsed-time member, and recommends placing the timer instruction before the rungs that use its values if those values should stay consistent through the scan.
Example 1: start and stop a motor with a seal-in
The classic first ladder program starts a motor with one push button and stops it with another. A push button only gives a signal while it is pressed, so the program needs a way to remember that the motor was started. That is the seal-in, also called a latch or holding contact.
Rung 1 reads: the Motor coil is on if (Start is pressed OR Motor is already on) AND Stop is not pressed. Here Start and Stop are bits that are 1 while their buttons are pressed. Follow it scan by scan:
- Nothing pressed. Start is 0, so its contact is open. Motor is 0, so the seal-in contact is open too. No power flow, Motor stays off.
- Start pressed. The Start contact closes, Stop’s normally closed contact passes power because Stop is 0, and the Motor coil turns on. At the end of the scan the output that drives the motor contactor switches on.
- Start released. The Start contact opens again, but the Motor contact in the parallel branch now reads the Motor bit, which is 1. The rung stays true. The motor has sealed itself in.
- Stop pressed. Stop becomes 1, so its normally closed contact opens and breaks the rung for both branches. The Motor coil turns off, the seal-in contact opens on the next scan because the Motor bit is now 0, and releasing Stop does not restart the motor.
If both buttons are pressed at once, Stop wins, because its contact is in series with everything. That is deliberate: in a seal-in, the stop condition always sits in series. Rung 2 shows that a coil’s bit can be read anywhere else in the program, here to light a run lamp.
This rung is control logic for running a machine. An emergency stop is a separate matter: the S7-1200 manual tells users to always install an emergency stop circuit for their application, and safety functions on machines are designed to standards such as IEC 62061, with safety-rated hardware.
Timers and counters are function blocks
Ladder handles time and counting with function blocks: boxes placed on a rung with named inputs and outputs. IEC 61131-3 defines a standard set, and the CODESYS Standard library, which implements the functions and function blocks defined in the standard, documents them. The three you meet first:
| Block | Name | Inputs | Output behavior |
|---|---|---|---|
| TON | On-delay timer | IN, PT (preset time) | Q turns on once IN has been on for PT; Q is off while IN is off, and IN going off resets the timer |
| TOF | Off-delay timer | IN, PT | Q is on while IN is on, and stays on for PT after IN goes off |
| CTU | Up counter | CU, RESET, PV (preset value) | Each rising edge on CU adds one to CV; Q is on when CV is greater than or equal to PV; RESET sets CV to 0 |
Each block also has an output for its current value: ET, the elapsed time, on the timers and CV, the count, on the counter. Every timer or counter you place is an instance with its own memory, which is why the software asks for a name or a data block when you drop one on a rung. Siemens uses the same names: the S7-1200 manual lists TP, TON, TOF and TONR as its IEC timers and CTU, CTD and CTUD as its counters.
Example 2: a cooling fan that runs on after the motor stops
A motor that stops should keep its cooling fan running for 30 seconds afterwards. That is exactly what an off-delay timer does.
The Motor bit from Example 1 drives the TOF block’s IN input. While the motor runs, IN is on, so Q is on and the fan runs. When the motor stops, IN goes off, the timer starts counting, and Q stays on until 30 seconds have elapsed. If the motor restarts within those 30 seconds, IN comes back on, the timer resets and the fan simply keeps running.
The mirror case uses TON. A level switch that chatters as liquid sloshes can feed a TON with a two second preset, and the alarm coil is driven from Q, so the alarm only comes on once the switch has stayed on for two full seconds. Any flicker shorter than that resets the timer.
Example 3: counting boxes with an up counter
A photoelectric sensor sees each box pass on a conveyor. After 12 boxes the case is full, and the conveyor should stop until an operator resets the count.
Rung 1 does the counting. Each time the photo eye goes from off to on, a rising edge on CU, the count CV goes up by one. A box that sits in front of the sensor for several scans still counts once, because the block reacts only to the rising edge. When CV reaches 12, Q turns on and so does CaseFull. Pressing the reset button sets CV back to 0, and Q turns off.
Rung 2 uses the result. The conveyor runs while the Motor bit is on and CaseFull is off; the normally closed CaseFull contact breaks the rung when the case is full.
The scan sets a limit here. The S7-1200 manual says the maximum counting rate of these software counters is limited by how often their program block runs: the block must run often enough to see every transition of the input. A target that passes the sensor faster than the scan can miss counts, and for fast signals the manual points to the CPU’s high-speed counters, which count in hardware.
When structured text is the better choice
Ladder is at its best for on and off logic: interlocks, permissives, start and stop circuits, alarms. It is also the easiest language for a maintenance technician to follow on a laptop in the middle of a breakdown, because it reads like the relay drawings electricians already know.
Structured text (ST), the textual language in IEC 61131-3, is the better choice when the logic is mostly arithmetic or data handling. Siemens’ version, SCL, is described in its S7-1200 manual as a high-level, Pascal-based language with IF-THEN-ELSE, CASE and REPEAT-UNTIL statements and loops. Consider ST for:
- Calculations. Scaling an analog value, a flow total, an average or a formula with several terms is one readable line in ST and a chain of math boxes in ladder.
- Loops and arrays. Checking 50 temperature readings for the highest one is a FOR loop in ST. Ladder has no natural way to iterate.
- State machines. A CASE statement on a step number lays out a machine sequence clearly. Sequential function chart is the other option for sequences.
- Strings and data. Building a barcode message or a record for a database is text work.
The choice can be made block by block. The S7-1200 manual notes that blocks written in SCL can be combined with blocks in LAD and FBD, and other IEC 61131-3 environments work the same way. A common split keeps interlocks and outputs in ladder, where they are easy to troubleshoot, and does the calculations in structured text, called from the ladder.
Sources
- IEC 61131-3:2025, programmable controllers, part 3: programming languages, ladder diagram and structured text as IEC 61131-3 languages, current edition
- Siemens, SIMATIC S7-1200 Programmable controller System Manual, 11/2011, A5E02486680-05, LAD networks, contacts, coils, series AND and parallel OR, no reverse power flow, set and reset coils, program execution in the scan, IEC timers and counters, timer update rules, software counter rate limit and high-speed counters, SCL, emergency stop circuit
- CODESYS, Standard library documentation, the functions and function blocks defined in IEC 61131-3
- CODESYS, TON function block, on-delay timer behavior
- CODESYS, TOF function block, off-delay timer behavior
- CODESYS, CTU function block, up counter behavior
- IEC 62061:2021, safety of machinery, functional safety of safety-related control systems, the standard for safety-related control systems on machines
- Mitsubishi Electric, MELSEC iQ-R safety CPU, ladder diagram listed among the programming languages of a current controller
Common questions
What is ladder logic in PLC programming?
Ladder logic is a graphical PLC programming language, standardized as ladder diagram (LD) in IEC 61131-3. A program is a stack of rungs drawn between two vertical rails. Contacts on each rung test the state of inputs and internal bits, and a coil at the right end of the rung sets an output or an internal bit to the result.
What is the difference between a normally open and a normally closed contact?
In ladder logic a normally open contact passes power when its bit is 1, and a normally closed contact passes power when its bit is 0. The names come from relay contacts. They describe how the contact reads a bit in the program, which is separate from how the physical switch on the machine is wired.
What is a seal-in circuit in ladder logic?
A seal-in, or latch, keeps a coil on after the button that turned it on is released. A normally open contact for the coil's own bit is placed in parallel with the start contact, so once the coil is on, that contact keeps the rung true until a stop contact in series breaks it.
Is ladder logic still used?
Yes. Ladder diagram is one of the languages in the current edition of IEC 61131-3, published in 2025, and current controllers such as the Siemens SIMATIC S7-1200 and the Mitsubishi Electric MELSEC iQ-R safety CPU list it among their programming languages. Many projects use it alongside structured text.
Should I use ladder logic or structured text?
Ladder suits on and off logic, interlocks and anything a maintenance technician has to follow on a live screen. Structured text suits calculations, loops over arrays, string handling and long chains of conditions. Most PLC software lets one project mix the two.
Written by Hamza Rivera. Facts in this article follow the editorial policy: each one is behavior that is well established or set by the standard named in the text. A confirmed error is fixed in the article and its Updated date changes.