PLC Basics • Ladder Logic • Beginner's Guide

What Is
Ladder Logic?
PLC Programming Explained (2026)

Merobix Engineering • • 10 min read

Ladder logic is the programming language that runs inside PLCs - the controllers that automate wellheads, compressors, pumps, and virtually every other piece of industrial equipment. If you've ever wondered how a wellhead automatically shuts down when pressure gets too high, or how a motor sequence starts in the right order every time, ladder logic is the answer. This guide explains it in plain English, with no prior programming experience required.

Back to Blog

What Is Ladder Logic?

Ladder logic is a graphical programming language used to program Programmable Logic Controllers (PLCs). It was developed in the 1970s as a way for electricians and engineers to program PLCs using a visual language that resembled the electrical relay diagrams they already knew how to read.

The name comes from its appearance: the program looks like a ladder lying on its side. Two vertical lines (called "rails") represent the power supply - the left rail is the live line, the right rail is the neutral or ground. Between the rails are horizontal lines called "rungs," each representing a logical condition or action. Electricity (or more accurately, logical power flow) travels from the left rail through the rung conditions to the right rail, turning outputs on or off depending on whether the conditions on each rung are met.

History and Why It Looks Like a Ladder

Before PLCs existed, industrial control systems were built from physical electrical relays - electromechanical switches that opened and closed based on electrical signals. Electricians drew these relay systems as ladder diagrams, with power rails on each side and relay contacts and coils on the rungs. When Modicon introduced the first commercial PLC in 1969, they designed the programming language to look like these familiar ladder diagrams so that electricians could transition to PLC programming without learning a new mental model. The language stuck, and today ladder logic remains one of the most widely used PLC programming languages.

How Electricians Relate to It

An experienced electrician who reads relay schematics can typically learn ladder logic in a few days. The XIC (Examine If Closed) contact in ladder logic is equivalent to a normally open relay contact in a relay schematic. The XIO (Examine If Open) contact is equivalent to a normally closed relay contact. The OTE (Output Energize) coil is equivalent to a relay coil. The logic is the same - only the medium changed from physical hardware to software.

Key insight: Ladder logic does not run sequentially like most programming languages. A PLC scans all rungs continuously - typically 100+ times per second - evaluating every rung on every scan. This is called the "scan cycle" and it is what makes PLCs suitable for real-time control.

Basic Ladder Logic Elements

Every ladder logic program is built from a small set of fundamental elements. Master these and you can read and write the majority of oil and gas PLC programs.

Normally Open Contact (NO) - XIC

A normally open contact passes logical power when its associated bit (tag) is TRUE (1). In Allen-Bradley ladder logic, this is the XIC instruction. In Siemens TIA Portal, it is the Normally Open contact in LAD. Think of it as a switch: when the bit is 1, the switch is closed, and power flows through. When the bit is 0, the switch is open, and power stops.

Example in oil and gas: A high pressure switch (PSH) has its output wired to a PLC input. When pressure exceeds the setpoint, the PSH closes, the PLC input bit goes TRUE, and any XIC contact referencing that bit passes power. If that contact is in series with an emergency shutdown valve (ESV) coil rung, the ESV energizes and closes the valve.

Normally Closed Contact (NC) - XIO

A normally closed contact passes power when its associated bit is FALSE (0) - the opposite of XIC. It is the Examine If Open instruction in Allen-Bradley. Think of it as a switch that is normally closed and opens when the bit turns on.

Example: A motor overload relay has a fault bit that goes TRUE when the motor draws too much current. A XIO (normally closed) contact on this fault bit is placed in series with the motor start output rung. Normally (when there is no fault), the XIO passes power and the motor can run. When an overload occurs, the bit goes TRUE, the XIO opens, power stops flowing to the motor output, and the motor stops.

Output Coil - OTE

The output coil (OTE - Output Energize) is placed at the right end of a rung. When the rung has power flowing through it (all conditions on the rung are met), the coil bit is set TRUE. When power stops flowing, the coil bit goes FALSE. The coil bit may control a physical output (a relay that energizes a motor starter) or an internal memory bit used in other rungs.

Simple Examples with Diagrams

The simplest possible ladder logic rung: a single XIC contact driving an OTE coil.

|----[XIC STOP_PB]--------------------( OTE PUMP_RUN )----| | |

This rung reads: "When the STOP_PB bit is TRUE, turn on PUMP_RUN." Not very useful in practice - the pump would only run while someone holds the stop pushbutton, which is backwards. Real motor control uses latching logic:

|----[XIC START_PB]----+----[XIO STOP_PB]----( OTE PUMP_RUN )----| | | | |----[XIC PUMP_RUN]----+ |

This reads: "Turn on PUMP_RUN if either the start button is pressed OR the pump is already running - but only if the stop button is not pressed." The PUMP_RUN XIC contact in parallel with the START_PB is called a "seal-in" or "latch" contact. It holds the pump running after the start button is released, until the stop button is pressed.

Timers and Counters

Timers and counters are essential elements in oil and gas PLC programs. They are available as function blocks (instructions) in all major PLC platforms.

TON - Timer On Delay

The TON instruction starts a timer when its input rung goes TRUE. After the programmed preset time, the timer's Done bit (DN) goes TRUE. If the input rung goes FALSE before the preset is reached, the accumulated time resets to zero.

Oil and gas example: After a high pressure alarm activates (input goes TRUE), the TON timer starts. After 10 seconds (preset = 10,000ms), the DN bit goes TRUE and activates the emergency shutdown valve output. The 10-second delay allows for pressure transients to settle without causing nuisance shutdowns, while still protecting equipment from sustained over-pressure conditions.

TOF - Timer Off Delay

The TOF instruction starts timing when its input rung goes FALSE (after having been TRUE). This is used for "cooldown" sequences where something needs to continue running after the main process stops.

Oil and gas example: After a compressor shuts down (input goes FALSE), a TOF timer runs the cooling fans for an additional 5 minutes. When the timer expires, the cooling fan output turns off.

CTU - Count Up

The CTU instruction increments an accumulated value each time its input transitions from FALSE to TRUE (a rising edge). When the accumulated value reaches the preset, the Done bit goes TRUE.

Oil and gas example: A rod pump jack unit uses a proximity switch on the walking beam to count strokes. Each stroke increments the CTU counter. After 100 strokes (preset = 100), the DN bit triggers a data log entry and resets the counter to track the next 100-stroke interval for pump efficiency calculations.

Ladder Logic in Oil and Gas

The following examples show how ladder logic applies to real oil and gas control scenarios. For the full context of how PLCs and SCADA work together, see our PLC programming for oil and gas guide.

High Pressure Shutdown Example

A wellhead high-high pressure protection rung:

|-[GRT TBG_PRESS 1200.0]-+--[XIO HIPPS_RESET]--(OTL HIPPS_LATCH)--| | | | |(If tubing pressure > 1200 PSI and reset not active, latch HIPPS) | |-[XIC HIPPS_LATCH]-------(OTE ESV_CLOSE)----------------------------| |(If HIPPS latched, energize the emergency shutdown valve to close) |

The GRT (Greater Than) comparison instruction returns TRUE when tubing pressure exceeds 1,200 PSI. The OTL (latch) instruction sets HIPPS_LATCH TRUE and holds it even after pressure drops back below the setpoint. An operator must physically press a reset button to clear the latch - ensuring someone acknowledges and investigates the over-pressure condition before restarting the well.

Motor Start Sequence Example

A safe motor start sequence checks permissive conditions before allowing the motor to start:

|--[XIC START_CMD]--[XIO MOTOR_FAULT]--[XIO LUBE_FAULT]--[XIC LUBE_PRESS_OK]--(OTL MOTOR_RUN)--| | (Start (No motor overload) (No lube fault) (Lube pressure okay) Latch motor on) | |--[XIC MOTOR_RUN]--(OTE MOTOR_START_OUTPUT)---------------------------------------| | (If motor run latch is set, energize the motor starter relay output) |

The motor can only start if all permissives are satisfied: no existing faults, adequate lubrication pressure. Each condition is in series - all must be TRUE simultaneously for power to flow. This is the "series AND" logic fundamental to all safety interlock programming.

Tank Level Control Example

A transfer pump controlled by tank level:

|--[GRT TANK_LEVEL 80.0]-----------------------------(OTL PUMP_ON_LATCH)--| | (If level > 80% full, latch pump on) | |--[LES TANK_LEVEL 20.0]-----------------------------(OTU PUMP_ON_LATCH)--| | (If level < 20% full, unlatch pump to stop transfer) | |--[XIC PUMP_ON_LATCH]--[XIO PUMP_FAULT]--(OTE PUMP_RUN_OUTPUT)-----------| | (Run pump if latched and no fault) |

The GRT (Greater Than) and LES (Less Than) comparison instructions provide hysteresis - the pump starts at 80% and stops at 20%, preventing rapid start/stop cycling as the level fluctuates near a single setpoint.

Ladder Logic vs Other Languages

Language Best For Oil & Gas Use Case
Ladder Logic (LAD) Safety logic, digital I/O, relay replacement Shutdown logic, motor interlocks, valve control
Function Block (FBD) Process control, analog signal flow PID loops, level control, separator automation
Structured Text (ST) Math calculations, data processing Flow calculations, gas composition, reporting
Sequential Function Chart (SFC) Step-by-step sequences Startup/shutdown sequences, batch processes

In practice, most oil and gas PLC programs use ladder logic for the majority of the code - digital safety logic, permissives, and status bits - with function blocks for PID control loops and structured text for calculations. A single TIA Portal or Studio 5000 project can use all languages simultaneously within different program sections. And when a project calls for production-ready code rather than practice rungs, our PLC programming and panel fabrication services cover both platforms.

How to Learn Ladder Logic

Free Simulators

The easiest way to start learning ladder logic is with a software simulator that runs on your PC without needing actual PLC hardware:

Recommended Resources

Getting Started with Allen-Bradley and Siemens

For oil and gas in Texas, learning Allen-Bradley Studio 5000 first is a practical path, as it is widely deployed in the region and well represented in local job postings. After learning the ladder logic fundamentals in Studio 5000, transitioning to Siemens TIA Portal takes days rather than weeks because the underlying concepts are identical. See our dedicated guides: Allen-Bradley PLC programming guide and Siemens PLC programming guide.

3 days To learn basic concepts
3 months To write simple programs
2–5 yrs To become an expert

Frequently Asked Questions

Is ladder logic still used?

Yes - ladder logic remains one of the most widely used PLC programming languages, particularly in North American oil and gas, manufacturing, and utilities. It remains popular because electricians and controls engineers who come from a relay background can read and troubleshoot it intuitively. Modern PLCs support all five IEC 61131-3 languages, and ladder logic is still widely used in the field today.

How long does it take to learn ladder logic?

The basic concepts - contacts, coils, timers, counters - can be learned in a few days using free simulation software. Becoming proficient enough to write and troubleshoot simple PLC programs takes 1–3 months of consistent practice. Becoming an expert who can design and commission complex compressor control or safety systems typically takes 2–5 years of hands-on field experience.

What software do I need for ladder logic programming?

For Allen-Bradley PLCs (widely used in Texas oil and gas), Studio 5000 Logix Designer is required, a paid subscription from Rockwell Automation. For Siemens S7-1200/1500, TIA Portal is required. Free alternatives for learning include Connected Components Workbench (Allen-Bradley Micro800), Codesys (generic IEC 61131-3), or TIA Portal trial licenses for simulation.

How do I read ladder logic?

Read ladder logic like a ladder on its side: the two vertical rails represent the power supply, and each horizontal rung is one logical condition or action. Logical power flows from the left rail through the rung's contacts to the output coil on the right - if every contact passes, the coil energizes. The PLC scans all rungs continuously, typically 100+ times per second, evaluating every rung on every scan cycle.

More in the Merobix Automation Fundamentals.

Sources and verification

This page references the vendor products and their official documentation published by the organizations below. Editions, product capabilities, and documentation change over time - confirm current requirements and specifications directly with the source.

Merobix is not affiliated with, endorsed by, or sponsored by these organizations; their names are used only to identify the standards and products discussed.

Free SCADA operator training
Merobix University - 70 video lessons & 261 quiz questions, from first login to compliance reporting. No demo call required.
Start free →