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
| Type | Size | Range | Use for |
|---|---|---|---|
| BOOL | 1 bit | 0 or 1 | Sensors, commands, status flags |
| BYTE | 8 bit | Bit pattern | Grouped flags, communication data |
| WORD | 16 bit | Bit pattern | Fault words, status words |
| INT | 16 bit | -32,768 to 32,767 | Small counts, step numbers |
| DINT | 32 bit | +/- 2.1 billion | Production totals, runtime seconds |
| REAL | 32 bit | Floating point | Scaled temperature, pressure, flow |
| TIME | 32 bit | Milliseconds | Timer presets and elapsed values |
| STRING | Variable | Characters | Batch 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.
| Approach | Result |
|---|---|
| Loose M bits per device | Works for two devices, unmanageable at twenty |
| One DB per device, hand built | Consistent until someone adds a field to only one |
| UDT with one instance per device | Change the UDT once, every device updates |
| UDT array indexed by device number | Enables 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.
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- TIA Portal with an S7-1200 or S7-1500 CPU, or PLCSIM
- An empty project you can experiment in
- Estimated time: 35 minutes
Create the UDT
Define a Motor UDT with command bits, status bits, an INT step, a DINT runtime and a WORD fault register.
Create instances
Add a data block containing three Motor instances, or an array of three.
Prove the INT overflow
Add an INT counter, increment it quickly in simulation and watch it pass 32,767.
Set retentive attributes
Mark the DINT runtime and a production counter retentive, then stop and restart the CPU.
Test a conversion
Convert a raw INT to REAL, scale it, and round it back for display.
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.
