Join our Newsletter — 33% off our NHI Course
Home› Guides› Top 20 Secure PLC Coding Practices Explained for…
Guide OT & IoT Security

Top 20 Secure PLC Coding Practices Explained for Engineers

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 14 November 2026 16 min read
On this page

Most PLC security effort sits around the controller, in firewalls, remote access and engineering workstations, while the logic inside the controller still trusts every value an HMI or a remote client writes to it. The Top 20 Secure PLC Coding Practices, version 1.0 published on 15 June 2021 by admeritia with support from the ISA Global Cybersecurity Alliance and the S4x events community, turn the PLC itself into a control: it validates its own inputs, checks its own code and reports when its own behaviour changes. This guide walks through all 20 practices one by one, explains what each defends against with MITRE ATT&CK for ICS references, gives the engineering detail needed to implement them, and shows how to introduce them on running plants without upsetting the process. It is written for controls engineers, system integrators, OT security leads and asset owners who write or accept PLC code. For the wider controller security picture (network, access, firmware, monitoring), start with the PLC Security Guide; this page goes deep on the code.

Key takeaways

  • The controller is the last line of defence. HMI checks, firewalls and passwords can all be bypassed; a range check inside the PLC still applies to a malicious write from any source.
  • Six objectives organise the list. The 20 practices are labelled against integrity of PLC logic, integrity of PLC variables, integrity of I/O values, hardening, resilience and monitoring, so you can see which gaps you are closing.
  • Most practices need no new product. Range checks, paired-signal interlocks, physical plausibility timers, cycle-time trends and code checksums use features already in common controllers.
  • Roles matter. Each practice names its target group: product supplier, integration or maintenance service provider, or asset owner. Put the right practice in the right contract.
  • Introduce at the next change, test off line. Adding logic changes scan time and behaviour, so practices go in through management of change, simulation and a test rig, never live edits on a running process.

What the Top 20 is and how it is organised

The list was modelled on the secure coding practices that exist for IT software and is published free at plc-security.com under a permissive licence (copy and reuse allowed with the copyright notice). It is vendor-neutral: where it gives examples it uses several manufacturers' features. Version 1.0 remains the current version listed on the project site as of November 2026.

Security objectivePracticesWhat it protectsATT&CK for ICS techniques it counters
Integrity of PLC logic1 to 5The program itself and the mode the controller runs inT0889 Modify Program; T0843 Program Download; T0858 Change Operating Mode; T0821 Modify Controller Tasking
Integrity of PLC variables6 to 10 (7 also resilience)Setpoints, presets, tags and registers written from outsideT0836 Modify Parameter; T0831 Manipulation of Control
Integrity of I/O values11 and 12Field measurements and their physical meaningT0835 Manipulate I/O Image; T0806 Brute Force I/O
Hardening13 and 14The communication surface of the controllerT0845 Program Upload and other remote access paths
Resilience7 and 15Safe behaviour under fault, restart or togglingT0816 Device Restart/Shutdown
Monitoring16 to 20Signals that something in the controller has changedT0878 Alarm Suppression; T0838 Modify Alarm Settings; T0832 Manipulation of View

The technique mapping is NHI Mgmt Group's reading of which behaviours each practice makes harder or more visible; the Top 20 document itself does not map to ATT&CK.

Practices 1 to 5: integrity of PLC logic

  • 1. Modularise PLC code: split the program into function blocks or subroutines by process function, for example start-up, inlet guide vane control and bleed valve control on a gas turbine, rather than one main routine. Test each module on its own, and record a hash of each tested module so later changes stand out. Reusable blocks can be protected by password or digital signature (know-how or block protection). Target group: product supplier.
  • 2. Track operating modes: the controller should run in RUN mode in production. Alarm the operator whenever it is not, and repeat the alarm near shift change so a controller left in PROGram or REMote mode after maintenance is not forgotten. Where there is no physical keyswitch, protect mode changes in the engineering software with a password. Alarms may be relaxed on a test system only when it is isolated from higher network levels.
  • 3. Leave operational logic in the PLC wherever feasible: totalisers, timers, interlocks, permissives and alarm thresholds belong in the controller, not in HMI scripts. If the HMI decides whether a button is enabled or when a motor may start, a compromised HMI or a direct protocol write skips the rule. Use the historian for trend analysis, not for control decisions. See the HMI and SCADA Server Hardening Guide.
  • 4. Use PLC flags as integrity checks: controllers set status flags for divide by zero, counter overflow, negative timer or counter presets and I/O scan overrun. Count them, alarm on them and investigate each. During unit testing, feed each module out-of-range values and confirm the flags behave as expected.
  • 5. Use cryptographic or checksum integrity checks for PLC code: compute a hash of the running program, or a checksum where the controller cannot hash, store a reference value and alarm on any change. The Top 20 cites the Rockwell ControlLogix change detection value read with a GSV instruction, and the Siemens S7-1500 GetChecksum instruction compared with a stored reference and logged with Datalog (manufacturers listed alphabetically). The check can also run from an engineering workstation or HMI on a schedule. The value is only useful if the reference is updated through change control, so every legitimate download produces a matching ticket.

Practices 6 to 10: integrity of PLC variables

  • 6. Validate timers and counters: limit the allowed preset range in logic. An alarm timer meant to run 1.3 seconds should not accept 5 minutes, and a counter meant to stop at 10,000 should not accept 11,000. Never let the HMI or a remote client write directly into a timer or counter preset: write into a staging tag, validate it, then copy it.
  • 7. Validate and alert for paired inputs and outputs: START and STOP, FORWARD and REVERSE, OPEN and CLOSE must never be true together. Block the combination in logic, raise an alarm when it is attempted, and add delay timers or independent outputs so equipment cannot be toggled fast enough to damage it. The document cites the 2007 Aurora Generator Test, where rapid out-of-sync breaker toggling caused physical equipment damage.
  • 8. Validate HMI input variables at the PLC level, not only at the HMI: HMI range checks protect against operator mistakes, not against someone writing to the controller with a protocol client. Repeat range and data type checks in the PLC. On a bad value, either substitute a safe default and flag it, or keep the last good value and log the rejection. Scale PID setpoints into consistent engineering units before validating, so a check on 0 to 100 bar is not applied to raw counts.
  • 9. Validate indirections: indirect addressing (array index from a variable) can be pushed out of bounds. Size arrays to a power of two, mask the index (for an 8-element array, AND with 0x07), place poisoned values such as -1 at each end, and alarm if a poisoned element is ever read or if the computed index differs from the masked one. Lookup tables for drive frequencies and pump rotation are typical candidates.
  • 10. Assign designated register blocks by function: group registers into read, write, validate and calculation areas. External clients then write only into a known block, logic validates from there, and network rules or protocol-aware firewalls can make other areas read-only. The Top 20 example uses a Siemens scratchpad flag area as the dedicated write block.

Practices 6 to 10 together are input validation for controllers, the same discipline as CWE-20 for IT software. See the CWE Top 25 Guide for the parallel.

Practices 11 and 12: integrity of I/O values

  • 11. Instrument for plausibility checks: cross-check measurements that describe the same physics. Pump flow totalised over time should match the change in tank level; heat input should match temperature rise; an independent data logger should agree with SCADA. Disagreement is either a failing instrument or manipulated data, and both deserve attention. This sometimes needs extra instrumentation, so it is easiest to specify at design.
  • 12. Validate inputs based on physical plausibility: every physical action has a credible duration. Time how long a gate takes to travel or a wet well takes to fill, and alarm on completion that is too fast, too slow or never happens. Clamp setpoints to what the equipment can physically do. The Top 20 cites the 2021 Oldsmar, Florida water treatment incident, where a requested chemical setpoint was far beyond any plausible value; a PLC-side limit would have refused it regardless of who typed it. See the Water and Wastewater Cybersecurity Guide.

Practices 13 and 14: hardening

  • 13. Disable unneeded or unused communication ports and protocols: draw the data flow diagram first, then for each physical port allow only the protocols that diagram needs. Controllers and communication modules often ship with HTTP, SNMP, Telnet, FTP or Modbus enabled; an embedded web server not used for maintenance should be off. This is ATT&CK mitigation M0942 Disable or Remove Feature or Program.
  • 14. Restrict third-party data interfaces: when another company or utility exchanges data with your controller (custody transfer metering, bulk water turnout flows), use a dedicated communication module, verify the other device's identity where the protocol allows, permit only the defined read and write registers, and run a watchdog timer so a stalled link is noticed. Where the controller cannot restrict access itself, put a data concentrator PLC or proxy in between. See the OT Third-Party and Integrator Access Guide.

Practice 15: resilience

  • 15. Define a safe process state in case of a PLC restart: for every output, decide whether a restart should energise, de-energise or hold the previous state, and document start-up and shut-down procedures. If a safe automatic restart is not possible, the controller should alarm and issue no new commands until an operator acts. Practice 7 also carries the resilience label because paired-signal protection prevents damage during abnormal sequences. Safety functions themselves stay in the safety instrumented system; see the Safety Instrumented Systems Security Guide.

Practices 16 to 20: monitoring

These five turn the controller into a sensor for its own integrity. Downloads, logic changes, forced restarts and rogue code all leave traces in cycle time, uptime, faults and memory.

PracticeWhat to recordAlarm onWhat a change can mean
16. Summarise PLC cycle times and trend them on the HMIAverage, peak and minimum scan time summarised every 2 to 3 secondsSignificant deviation from a reference value set after commissioningAdded or removed logic, extra communication load, a task change
17. Log PLC uptime and trend it on the HMIUptime counter in the PLC, or SNMP MIB-2 sysUpTime (OID 1.3.6.1.2.1.1.3) polled externallyAny reset of uptimeRestart, power loss, firmware or program download
18. Log PLC hard stops and trend them on the HMIFault and shutdown events, error codes, first scan after power-up, all time-synchronised (for example to syslog)Any hard stop, checked by the HMI before restart is allowedFault injection, malformed traffic, deliberate stop
19. Monitor PLC memory usage and trend it on the HMIMain, I/O and logic or tag memory against a per-controller baselineDeviation from the baselineNew code, new tags or blocks loaded outside change control
20. Trap false negatives and false positives for critical alertsEach critical alarm bit and, separately, the conditions that should set itBit off while conditions are true, or on while they are falseAlarm suppression (as in the Triton attack on a safety system) or injected false alarms

These signals are most useful when they leave the controller. Forward them to the historian and to OT network monitoring so a security analyst sees them alongside protocol events such as program downloads and mode changes. See the OT Network Security Monitoring Guide.

How to implement on running plants

  1. Baseline: export every controller's program, record current checksums, cycle times, memory use and enabled services. Store the exports as the golden copy. See the OT Backup, Recovery and Golden Image Guide.
  2. Start with the observe-only practices: 2, 5, 16, 17, 18 and 19 add monitoring without changing control behaviour. Alarm to a non-intrusive priority first and tune thresholds for several weeks.
  3. Prioritise by consequence: use the OT risk assessment to find the setpoints and interlocks whose manipulation could cause harm, damage or environmental release, and apply 6, 7, 8 and 12 there first. See the OT Cyber Physical Risk and Safety Guide.
  4. Change through management of change: every new check is a logic change. Raise it through the plant's change process, review it with process and safety engineers, and schedule it into a planned outage or a controller that supports online edits safely.
  5. Test off line: run the modified program on a simulator or test rig with normal, boundary and out-of-range inputs, measure the scan time impact and confirm alarm behaviour.
  6. Deploy with a rollback: keep the previous program version and its checksum ready, deploy, compare the new checksum to the tested build, and update the reference value only after sign-off.
  7. Write it into new projects: add the practices, by number, to functional design specifications and factory and site acceptance tests so integrators deliver them by default.

Decision guidance: who does what, and where to compromise

SituationRecommended approachTrade-off
New system or major upgradeSpecify all applicable practices in the design specification and acceptance tests; make modularisation (1) and register blocks (10) structural.Slightly more engineering time and controller memory up front.
Legacy controller with little spare scan timePrefer external checks: practices 5, 17 and 19 run from an engineering workstation or monitoring tool, and validation is added only to the highest-consequence tags.Detection is slower than in-controller checks.
Product supplier (OEM skid, packaged unit)Own practices 1, 4, 7, 8, 9 and 10 in the shipped code and document safe restart (15).Asset owners need to request this in procurement; see the OT Product Procurement Guide.
System integrator or maintenance providerCarries most practices, especially 11 to 14 and the monitoring group 16 to 20.Needs a clear owner for alarm response once handed over.
Small site with no OT security teamPractices 2, 8, 12 and 13 give the most protection for the least effort; route monitoring alarms to the control room.Operators must know which alarms are security relevant.

Where identity fits

Several practices assume you know who changed the controller. Mode changes (2), code changes (5) and parameter writes (8) are only attributable if engineering workstations and HMIs use named accounts, project passwords and controller access protection are managed as credentials, and integrators connect through brokered remote access. Shared engineering passwords make every checksum alarm an investigation with no suspect. See the OT and ICS Identity and Access Guide and the Engineering Workstation Security Guide.

Measuring progress

  • Coverage: percentage of high-consequence controllers with code integrity checks (practice 5) and uptime or restart alarms (17) in place.
  • Validated writes: share of HMI-writable setpoints that pass through PLC-side validation (6 and 8).
  • Unexplained changes: number of checksum, memory or cycle-time alarms with no matching change ticket (target zero, every one investigated).
  • Exposed services: count of enabled protocols per controller against the data flow diagram (13).
  • Alarm integrity: critical alarms with a false negative and false positive trap (20).

Common failure patterns

  • Validation only in the HMI: the most common gap. Any client that speaks the controller's protocol can bypass HMI limits.
  • Checksums nobody watches: integrity values are computed but the reference is never updated after legitimate changes, so alarms are permanently on and ignored.
  • Controllers left in PROGram or REMote mode: left after commissioning or maintenance, which allows downloads without a physical step.
  • Live edits to add security logic: unvalidated online changes cause trips, which then discredit the programme.
  • Monitoring that stops at the HMI: cycle-time and restart alarms reach the operator but never the security team, so a pattern across several controllers goes unnoticed.

Framework mapping

Practice groupNIST SP 800-53 Rev 5NIST CSF 2.0ATT&CK for ICS mitigation
Logic integrity (1 to 5)SI-7 Software, Firmware, and Information Integrity; CM-3 Configuration Change ControlPR.PS-01M0945 Code Signing; M0947 Audit
Variable and I/O validation (6 to 12)SI-10 Information Input ValidationPR.DS-01M0800 Authorization Enforcement
Hardening (13 and 14)CM-7 Least Functionality; SC-7 Boundary ProtectionPR.PS-01M0942 Disable or Remove Feature or Program; M0937 Filter Network Traffic
Resilience (15)SI-17 Fail-safe ProceduresPR.IR-03Not mapped (design-level control)
Monitoring (16 to 20)SI-4 System Monitoring; AU-6 Audit Record ReviewDE.CM-09M0947 Audit

For the OT standards context, NIST SP 800-82 Rev. 3 (September 2023, with a Revision 4 draft out for comment in late 2026) and the IEC 62443 series apply; see the NIST SP 800-82 OT Security Guide and the IEC 62443-4-1 and 4-2 Secure Product Development Guide.

Practitioner checklist

  • Export and baseline every controller program, checksum, cycle time and memory figure.
  • Alarm when any controller leaves RUN mode, and re-alert at shift change.
  • Compute code checksums on a schedule and tie each reference update to a change ticket.
  • Repeat HMI range and type checks inside the PLC for every writable setpoint.
  • Interlock paired signals and add anti-toggling delays.
  • Add physical plausibility timers and setpoint clamps to high-consequence loops.
  • Disable every port and protocol not on the data flow diagram.
  • Define and document the safe restart state of every output.
  • Trend cycle time, uptime, hard stops and memory, and forward them to security monitoring.
  • Write the practices, by number, into design specifications and acceptance tests.

Standards and references

Related NHI Mgmt Group resources: PLC Security Guide · Rockwell ControlLogix and FactoryTalk Hardening Guide · Siemens SIMATIC S7 and TIA Portal Hardening Guide · OT Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 14 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.