Try a PLC free — no signup
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;

Free · no signup to try

Run this block in your browser

Try the instruction on a live rung before you copy it into a project — nothing to install.

Try it in your browser — no signup

Opens plcsimulationsoftware.com — same team

Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad

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.

Free · no signup to try

Wire this block up and run it

Drop the instruction into a rung, press Run and watch it execute in your browser — then adapt it to your vendor tool.

Try it in your browser — no signup

Opens plcsimulationsoftware.com — same team

Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad