Learn PLCs free
Math OperationsBeginnerIEC 61131-3

SUB (Subtraction)

Subtracts second input from first input, outputs the difference.

The SUB function block subtracts the second input from the first input and outputs the difference. It is used for calculating deviations, error signals (setpoint minus process value), position differences, and remaining quantities in PLC programs.

Parameters

Inputs

NameTypeDescription
IN1ANY_NUMMinuend (value to subtract from)
IN2ANY_NUMSubtrahend (value to subtract)

Outputs

NameTypeDescription
OUTANY_NUMDifference (IN1 - IN2)

Ladder Logic Example

// Ladder Logic - SUB (Error Calculation)
//
// |----[SUB]----|
// | IN1: Setpoint        |
// | IN2: Process_Value   |
// | OUT: Error_Signal    |

Structured Text Example

Error_Signal := Setpoint - Process_Value;
Remaining := Total_Qty - Consumed_Qty;

20 Production-Ready Ladder Logic Templates

Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.

Platform-Specific Implementation

S

Siemens (TIA Portal)

Use SUB instruction in TIA Portal.

AB

Allen-Bradley (Studio 5000)

Use SUB instruction in Studio 5000.

C

CODESYS

Use - operator in ST or SUB function block.

Common Applications

  • PID error calculation
  • Position deviation
  • Remaining quantity
  • Differential pressure
  • Time difference

Frequently Asked Questions

What is SUB (Subtraction) in PLC programming?

Subtracts second input from first input, outputs the difference. The SUB function block subtracts the second input from the first input and outputs the difference. It is used for calculating deviations, error signals (setpoint minus process value), position differences, and remaining quantities in PLC programs.

What are common applications of SUB (Subtraction)?

SUB (Subtraction) is commonly used for: PID error calculation, Position deviation, Remaining quantity, Differential pressure, Time difference.

How do I use SUB (Subtraction) in different PLC platforms?

Siemens: Use SUB instruction in TIA Portal. Allen-Bradley: Use SUB instruction in Studio 5000. CODESYS: Use - operator in ST or SUB function block.

Stop Writing Ladder Logic From Scratch

Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.

20
Ready-Made Templates
LD + ST
Both Languages Included
$29
One-Time Purchase
Get Instant Access -- $29

Instant download - 30-day money-back guarantee - Use on unlimited projects

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →