Skip to content
Right-angle M12 female cordset with yellow sensor cable

M12 Connector Pinout and Color Code: 4-Pin, 5-Pin, 8-Pin and Coding Types

The M12 connector is the standard plug on industrial sensors, actuators, IO-Link devices and industrial Ethernet. "M12" is the 12 mm thread; the pin count and the coding (the key that stops the wrong plugs mating) tell you what it is for. Here are the pinouts you will meet most often.

M12 4-pin (A-coded): sensors and actuators

Pin Wire color Typical function (3- or 4-wire DC sensor)
1 Brown +V (10–30 V DC)
2 White Second output, NC output, or diagnostic
3 Blue 0V
4 Black Main output (NO); C/Q line on IO-Link devices

A 3-wire sensor uses pins 1, 3 and 4 and leaves pin 2 empty, so a standard 4-pin cordset fits both. These colors follow IEC 60947-5-2; most brands match, but always check the device datasheet.

M12 5-pin (A-coded)

Same as 4-pin, plus pin 5 (gray) in the center. Pin 5 is used for functional earth on some devices, a second signal on others, and the extra isolated power on IO-Link Class B ports. A 4-pin cordset will plug into a 5-pin device, but pin 5 will not be connected.

M12 8-pin (A-coded)

Pin Wire color
1 White
2 Brown
3 Green
4 Yellow
5 Gray
6 Pink
7 Blue
8 Red

Eight-pin cordsets follow the DIN 47100 color sequence, which is different from the 4-pin code: pin 1 is white here, not brown. Pin functions depend entirely on the device (encoders, valve islands, multi-signal sensors), so wire from the device manual.

M12 4-pin D-coded: industrial Ethernet

Pin Signal PROFINET color
1 TD+ Yellow
2 RD+ White
3 TD– Orange
4 RD– Blue

D-coded M12 carries 100 Mbit/s Ethernet (EtherNet/IP, PROFINET, EtherCAT, Modbus TCP). For gigabit and faster, use 8-pin X-coded.

M12 coding types at a glance

Coding Used for
A Sensors, actuators, DC power, IO-Link (3 to 12 pins)
B PROFIBUS and some fieldbuses
C AC sensors and actuators
D 100 Mbit/s Ethernet
X 1–10 Gbit/s Ethernet, 8-pin
S AC power
T DC power
L Higher-current DC power, for example PROFINET power distribution

The coding key is a small notch or rib in the insert. Different codings will not mate, which protects a 24 V sensor from being plugged into an AC or Ethernet port.

Male vs. female and reading the pin numbers

Sensors usually have a male receptacle (pins), and the cordset has a female socket. Pin numbering is mirrored between the two when you look at their faces, which is the most common reason for a "wrong pinout." Always check whether a diagram shows the male or female face.

M8 and other sensor connectors

  • M8 3-pin: pins 1 (brown, +V), 3 (blue, 0V), 4 (black, output). Same colors and numbers as M12, smaller thread.
  • M8 4-pin: adds pin 2 (white).
  • 1/2"-20 UNF (micro-style): common on AC sensors in North America.
  • 7/8"-16 UN (mini-style): heavier-duty power and AC connections.

Choosing a cordset

  1. Match size, pin count and coding to the device.
  2. Choose straight or right-angle to suit the mounting space.
  3. Pick the jacket: PVC for general use, PUR for oil and flexing (cable tracks), TPE or silicone for high temperature or washdown.
  4. Choose length, or a double-ended cable to run to a distribution block.

HTM offers M8, M12, 1/2-20 and 7/8 cordsets, double-ended cables and splitters in PVC, PUR, TPE and silicone. Browse HTM sensor cables and connectors and distribution blocks.

Frequently asked questions

Can I use a 5-pin cable on a 4-pin sensor?
Yes. The 5-pin female socket accepts a 4-pin male plug, and pins 1–4 line up.

Are M12 connectors waterproof?
Typically IP67 when mated and hand-tightened. Unused ports need a sealing cap.

Why does my sensor work on one cable but not another?
Usually a different pin assignment for pin 2 or 4, or a male/female diagram mix-up. Compare both datasheets.

Need a specific cordset? Call 1-800-724-4209 or request a quote with the connector, pin count and length.

Previous article Sinking vs. Sourcing: PLC Inputs and Outputs Explained
Next article How to Wire a Proximity Sensor: 2-Wire, 3-Wire, PNP and NPN Diagrams Explained