X12 Data Types
Every X12 element has a data type that controls how values are encoded in EDI. The type determines what characters are allowed, whether decimal points are written, how dates and times are formatted, and which code list a value must come from.
Generating compliant EDI requires knowing each element's type - the same source value can produce very different output depending on whether the target is an N2, an R, or an AN.
AN Alphanumeric
Freeform string of letters, digits, and most printable characters. Usage guides define meaning; X12 only enforces length.
| Source value | Encoded value | Note |
|---|---|---|
"Acme Trucking" |
ACME TRUCKING |
Typically sent uppercase; leading/trailing spaces trimmed. |
"PO-12345" |
PO-12345 |
Hyphens and digits are allowed. |
- Min/max length is enforced - an AN 1/30 field will reject a 31-character value.
- Element separators, segment terminators, and the release character (often ~, *, and ?) must be escaped or avoided within the value.
ID Identifier
The value must come from a specific X12 code list defined for that element. Anything outside the list is invalid.
| Source value | Encoded value | Note |
|---|---|---|
"Accepted" |
A |
B1-04 Reservation Action Code: source boolean/label mapped to the X12 code. |
"Declined" |
D |
Same element, opposite outcome. |
- Code lists can be narrowed by a trading partner: the X12 list might allow 20 values but the partner only accepts 3.
- Element pages in this reference list all allowed codes for the standard X12 list.
N Numeric
Integer value. Equivalent to N0. No decimal point is written.
| Source value | Encoded value | Note |
|---|---|---|
42 |
42 |
Integers pass through unchanged. |
-5 |
-5 |
Negative sign is allowed when the element permits it. |
- If your source value has a decimal component, you must round or truncate before encoding.
Nn Numeric with implied decimals
Fixed-point numeric with n implied decimal places. The decimal point is NOT written in EDI - the receiver multiplies by 10^-n.
| Source value | Encoded value | Note |
|---|---|---|
12.56 |
1256 |
N2: two implied decimals, so 12.56 -> 1256. |
100 |
10000 |
N2: 100 has two implied decimals of zero. |
3.5 |
35000 |
N4: four implied decimals, so 3.5 -> 35000. |
0.07 |
7 |
N2: leading zeros before the implied point are dropped. |
- Generating compliant output from a source value like 12.56 requires knowing this is an N2 field - you cannot do it with string interpolation alone.
- Rounding strategy (half-up vs. banker's) is not defined by X12; pick one and apply it consistently.
R Decimal
Decimal number where the decimal point IS written. The point is optional for integer values.
| Source value | Encoded value | Note |
|---|---|---|
12.56 |
12.56 |
Decimal point is preserved. |
100 |
100 |
No point needed for a whole number. |
0.5 |
.5 |
Leading zero may be dropped; trailing zeros after the point may be trimmed. |
- R is the 'normal' decimal type most developers expect - unlike Nn, what you see is what is transmitted.
- Some trading partners restrict the number of decimal places or forbid scientific notation.
DT Date
Calendar date. Format depends on max length: CCYYMMDD (8) or YYMMDD (6).
| Source value | Encoded value | Note |
|---|---|---|
"2026-04-01" |
20260401 |
DT length 8: CCYYMMDD. |
"2026-04-01" |
260401 |
DT length 6: YYMMDD, century inferred (usually sliding window). |
- CCYYMMDD is preferred and nearly universal in modern implementations. YYMMDD appears in older guides and is ambiguous across centuries.
- The element's min/max length tells you which format to emit.
TM Time
Time of day. Format depends on length: HHMM (4), HHMMSS (6), HHMMSSD (7), or HHMMSSDD (8). 24-hour clock.
| Source value | Encoded value | Note |
|---|---|---|
"14:30" |
1430 |
TM length 4: HHMM. |
"14:30:45" |
143045 |
TM length 6: HHMMSS. |
"14:30:45.2" |
1430452 |
TM length 7: HHMMSSD (tenths). |
- Time zone is not part of the value - X12 has a separate TZ qualifier in some segments for that purpose.
- Leading zeros must be preserved: 9:05am is 0905, not 905.
B Binary
Raw binary data. Rarely used in modern trading; when present, length is declared by a preceding element and the segment terminator is suppressed.
| Source value | Encoded value | Note |
|---|---|---|
(bytes) |
(bytes) |
No encoding transformation - bytes are passed through verbatim. |
- Most trading partners avoid B and prefer base64-encoded payloads in an AN field, or attachments via a separate channel.
The type in isolation doesn't tell you everything. A trading partner's implementation guide can narrow an X12 code list, shorten a length range, or mark an otherwise-optional element as required. Compliant generation requires both the X12 standard and the partner's guide - which is why Tediware drives EDI generation from a schema derived from both.