PLC Programming · Technical Blog

Siemens PLC Data Types and Memory Areas Explained

Pick the wrong data type and your counter overflows at 32,767 in the middle of a night shift. This guide covers the Siemens data types, the memory areas they live in, and how to structure data so a program stays maintainable.

2,500+ engineers trained 4.9/5 Google rating 21+ years, Chinchwad, Pune Next batch: contact for dates
Quick answer

BOOL for single bits, INT for values up to 32,767, DINT for larger counts, REAL for scaled measurements, and WORD or DWORD for grouped status and fault bits. Inputs and outputs live in the process image (I and Q), internal bits in M memory, and structured application data in data blocks. Use optimized data blocks with symbolic access for new projects.

  • An INT holds 32,767; production counters and runtime seconds need DINT.
  • Never mix a REAL and an INT in the same calculation without an explicit conversion.
  • Optimized data blocks with symbolic names are faster and safer than absolute addressing into standard blocks.

The Siemens Data Types and When to Use Each

TypeSizeRangeUse for
BOOL1 bit0 or 1Sensors, commands, status flags
BYTE8 bitBit patternGrouped flags, communication data
WORD16 bitBit patternFault words, status words
INT16 bit-32,768 to 32,767Small counts, step numbers
DINT32 bit+/- 2.1 billionProduction totals, runtime seconds
REAL32 bitFloating pointScaled temperature, pressure, flow
TIME32 bitMillisecondsTimer presets and elapsed values
STRINGVariableCharactersBatch IDs, part numbers, messages

The most common production bug in this area is an INT used for a shift counter. It counts happily to 32,767 and then wraps to a large negative number. Use DINT for anything that accumulates.

The second is REAL used where it is not needed. A REAL comparison for exact equality almost never behaves as expected because of floating point rounding; compare against a range instead.

Memory Areas: I, Q, M and DB

Every tag lives somewhere, and where it lives changes how it behaves.

  • I, the process image input: a snapshot of the physical inputs taken at the start of each scan. Your program reads a stable copy, not a live signal.
  • Q, the process image output: written by your program during the scan and transferred to the physical outputs at the end of it.
  • M, bit memory: internal flags with no physical connection. Convenient, but a program built on hundreds of loose M bits becomes impossible to follow.
  • DB, data blocks: structured application data. This is where machine data, setpoints, recipes and HMI interfaces belong.
  • L, temporary local data: valid only inside one block call, cleared afterwards. Never store machine state here.

The process image is why an input changing twice within one scan is only seen once. That behaviour is explained fully in the PLC scan cycle.

Direct peripheral access with :P reads or writes the module immediately, bypassing the process image. Use it only where microseconds genuinely matter, because it costs communication time on every access.

Structuring Data with UDTs and Data Blocks

A user defined type is a data structure you design once and reuse. Define a Motor UDT containing command bits, status bits, runtime and fault word, then create one instance per motor.

ApproachResult
Loose M bits per deviceWorks for two devices, unmanageable at twenty
One DB per device, hand builtConsistent until someone adds a field to only one
UDT with one instance per deviceChange the UDT once, every device updates
UDT array indexed by device numberEnables loops and generic function blocks

Optimized versus standard data blocks

Optimized blocks store data in the order the CPU handles most efficiently and are accessed only by symbolic name. Standard blocks keep a fixed byte layout and allow absolute addressing, which is needed for some older communication partners and for certain HMI or third-party accesses.

Use optimized for everything unless a communication partner forces otherwise. Absolute addressing into a data block is a maintenance trap: insert one variable and every address after it shifts.

Structured tags also make WinCC and HMI configuration far cleaner; see WinCC tag types.

Learn structured PLC programming

Siemens sessions covering UDTs, function blocks, instance data and reusable machine code.

Book a Free Demo Class

Conversions, Overflow and Retentive Memory

Siemens will not silently mix types. Converting between them is explicit, and that is a feature.

  • CONV or CONVERT: the general instruction for INT to DINT, DINT to REAL and similar.
  • ROUND, TRUNC, CEIL, FLOOR: control exactly how a REAL becomes an integer.
  • NORM_X and SCALE_X: the pair used for analog scaling, covered in analog input scaling.
  • MOVE with matching types: the safest way to copy values between structures.

Overflow

Check the ENO output or the status bits on arithmetic where an overflow is possible. A runtime seconds counter in INT overflows in nine hours; in DINT it runs for sixty-eight years.

Retentive memory

Mark counters, totals and recipe data retentive so they survive a power cycle. Set the retentive range for M memory in the CPU properties, and the retain attribute per variable in a data block. Everything else should start from a known state at power-up, because a half-remembered machine state is more dangerous than a clean restart.

Hands-On Lab: Build a Motor UDT and Prove an Overflow

Hands-on
Before you start
  • TIA Portal with an S7-1200 or S7-1500 CPU, or PLCSIM
  • An empty project you can experiment in
  • Estimated time: 35 minutes
1

Create the UDT

Define a Motor UDT with command bits, status bits, an INT step, a DINT runtime and a WORD fault register.

The UDT appears under PLC data types and can be used as a variable type.
2

Create instances

Add a data block containing three Motor instances, or an array of three.

All three share an identical structure with symbolic names.
3

Prove the INT overflow

Add an INT counter, increment it quickly in simulation and watch it pass 32,767.

The value wraps to a large negative number, demonstrating why DINT is required.
4

Set retentive attributes

Mark the DINT runtime and a production counter retentive, then stop and restart the CPU.

Retentive values survive the restart while non-retentive values clear.
5

Test a conversion

Convert a raw INT to REAL, scale it, and round it back for display.

No compile errors and the displayed value matches the calculation.
Checkpoint—how to know you did it right

One UDT change updates every motor instance, the overflow is reproducible on demand, and retentive data survives a CPU restart.

Frequently asked questions

When should I use DINT instead of INT?

Whenever a value accumulates. INT stops at 32,767, so production counts, runtime seconds and totalisers need DINT.

What is the difference between optimized and standard data blocks?

Optimized blocks store data in the CPU's preferred order and are accessed only symbolically. Standard blocks keep a fixed byte layout and allow absolute addressing, which some older partners require.

Why does my REAL comparison never trigger?

Floating point values are rarely exactly equal to a constant. Compare against a range or use a tolerance instead of testing for exact equality.

What does retentive memory actually protect?

Values you need after a power cycle, such as production counters, runtime hours and recipe parameters. Machine state and commands should normally start clean.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience

Get the full syllabus + free demo class

Share your details—a Softwell training advisor will contact you with batch dates, fees and hardware-practice options.

No spam. Used only to share course details for this enquiry.

Learn with practical industrial examples

Join live online, Pune classroom or corporate in-plant automation training.

Request Course Details
Verified learning pathway

Discuss Siemens PLC Data Types and Memory

Explore practical curriculum, software, hardware and batch options for this technology.

Content reviewed: 09 September 2026

Siemens PLC & TIA Portal Learning Path

Continue with the related Siemens PLC tutorials in this practical learning series.

  1. SCL vs Ladder Logic
  2. Upload PLC Program
  3. TIA Selection Tool
  4. Analog Input Scaling
  5. PLC Counters
  6. PLC Timers
  7. Addressing & Data Types
  8. Hardware & PLC Tags
  9. OB, FB, FC & DB
☎ Call WhatsApp ✉ Email Enquire Now