Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
All diagram types

Mermaid Packet Diagram Syntax & Header Examples

A packet diagram is a bit layout. Each line is a field, from a start bit to an end bit, with a label.

Examples

Copy an example, or open it in the live editor with this diagram already loaded.

UDP header

Four 16-bit fields. The range is inclusive: 0-15 is 16 bits, starting at bit 0.

packet-beta
    0-15: "Source Port"
    16-31: "Destination Port"
    32-47: "Length"
    48-63: "Checksum"

TCP flags

Single-bit fields use one number. Wider fields use a range. This is the flag byte area of a TCP header, not the whole header.

packet-beta
    0-3: "Data Offset"
    4-9: "Reserved"
    10: "URG"
    11: "ACK"
    12: "PSH"
    13: "RST"
    14: "SYN"
    15: "FIN"

Custom message header

The same syntax documents an internal binary format. Pick bit numbers that match the struct you actually write.

packet-beta
    0-7: "Version"
    8-15: "Type"
    16-31: "Length"
    32-63: "Request id"

What is a Packet Diagram?

A Mermaid packet diagram documents a binary header the way an RFC does. The diagram starts with packet-beta. A field is either start-end: "Label" for a range or bit: "Label" for a single flag. Bits are numbered from 0, and Mermaid wraps the drawing into rows. Use it for a protocol header or a binary file format. It is not a network topology; boxes and arrows between servers belong on an architecture or block diagram.

When to use it

Use a packet diagram when the subject is bits and field widths. Use an architecture diagram for hosts and networks. Use a flowchart for the protocol's behavior rather than its header.

Edit this packet diagram in the live editor, read the Mermaid cheat sheet, or compare it with Block Diagram, Flowchart and Architecture Diagram.

Common Use Cases

  • •Protocol documentation - Visualize TCP, UDP, IP, and custom protocol headers
  • •Network engineering - Document packet structures for implementation
  • •RFC diagrams - Create standard protocol header visualizations
  • •Binary format design - Define data serialization layouts
  • •Education - Teach networking concepts with clear packet visualizations

Syntax Quick Reference

ElementSyntaxDescription
Single bitN: "Label"One-bit field at position N
Bit rangeN-M: "Label"Multi-bit field from N to M
Field label"Field Name"Name of the packet field

Syntax tips

  • •Start with packet-beta. Each field is one line.
  • •A range is inclusive: 0-15 is sixteen bits. A single flag is one number: 10: "ACK".
  • •Number bits from 0, in the order the fields appear in the header.
  • •Quote every label. Spaces in the label are fine inside the quotes.
  • •Do not leave a gap by accident. If bit 16 is unused, add a Reserved field so the next range starts at the right bit.

Common mistakes

Counting 0-15 as 15 bits.

The ends are inclusive. 0 through 15 is 16 bits. The next field starts at 16.

Overlapping ranges, such as 0-15 and 15-31.

The next field starts at the bit after the previous end. 0-15 is followed by 16-31.

Using a packet diagram to draw routers and servers.

Packet diagrams are bit fields. Draw the network with an architecture or block diagram.

Export Options

Header diagrams are documentation. SVG stays readable when the page is zoomed onto a flag. Free PNG exports include a watermark.

Got Mermaid code from ChatGPT? Paste it here to render and export instantly.

Get the Free Mermaid Syntax Cheat Sheet

Free Mermaid Syntax Cheat Sheet

All 21 diagram types in one PDF reference.

Frequently Asked Questions

Ready to create your own packet diagram?

Open the editor with this example pre-loaded and start customizing.

Packet Diagram templates

Related Diagram Types

All diagram types