File types · Explainer

The XWD file (.xwd)

An XWD file is an X Window Dump: a screenshot of a window or a whole screen taken with the xwd tool on the X Window System, stored as a header that describes the display, a colour map and the raw pixels. This guide explains what's inside one, how to take and view dumps with xwd and xwud, and how to open and convert them.

At a glance

Full name
X Window Dump
Extensions
.xwd
MIME type
None registered with IANA; image/x-xwindowdump by convention
Kind
Binary raster image, uncompressed; the pixels are stored as the X server held them
Standard or owner
The X Window System; defined by the header file XWDFile.h, now in X.Org's xorgproto
First released
With X10 in 1985; the X11 format, file version 7, since 1987
Header
100 bytes: 25 big-endian 32-bit numbers, followed by the window name
Magic number
None as such; bytes 4 to 7 are the file version, 00 00 00 07
Colours
Whatever the display used: 1-bit to 32-bit pixels, with a colour map or direct colour
Opens with
xwud, GIMP, ImageMagick, Netpbm, XnView and FFmpeg; not web browsers

The basics

What is an XWD file?

XWD is the screenshot format of the X Window System, the graphics system behind traditional Unix and Linux desktops. The xwd program, short for X window dump, asks the X server for the contents of a window, or of the whole screen, and writes them to a file. The companion program xwud (X window undump) shows the file again in a window.

xwd first appeared with X10 in 1985 and was carried into X11 in 1987; X.Org still ships both tools. Because an X client can request the contents of any window with Xlib's XGetImage, a dump is a plain copy of what the server has: the header records exactly how the display stored pixels, and the data follows in that form.

That makes XWD files easy to write and faithful, but they're large and depend on the machine that made them. Use them to capture an X display, then convert to PNG to keep or share the result. You'll also meet XWD files in old documentation and bug reports from Unix workstations, and as an output option in tools such as ImageMagick and Netpbm.

Anatomy

What's inside an XWD file

An XWD file is a 100-byte header, the name of the window, a colour map and the pixels. The header's numbers are 32-bit and big-endian. Below is every byte of a 192-byte file we made for this page with Netpbm's pnmtoxwd and checked with ImageMagick and FFmpeg: 3 × 2 pixels, red, green and blue over yellow, white and black, stored as 8-bit colour-map indexes. It isn't offered for download.

tiny.xwd (hex, 192 bytes)
tiny.xwd: 3 × 2 pixels, 8-bit PseudoColor, 192 bytes

offset  bytes          header field (32-bit, big-endian)
000000  00 00 00 72    header_size: 114 (100 + window name)
000004  00 00 00 07    file_version: 7
000008  00 00 00 02    pixmap_format: 2 (ZPixmap)
00000C  00 00 00 08    pixmap_depth: 8
000010  00 00 00 03    pixmap_width: 3
000014  00 00 00 02    pixmap_height: 2
000018  00 00 00 00    xoffset: 0
00001C  00 00 00 01    byte_order: 1 (MSBFirst)
000020  00 00 00 08    bitmap_unit: 8
000024  00 00 00 01    bitmap_bit_order: 1 (MSBFirst)
000028  00 00 00 08    bitmap_pad: 8
00002C  00 00 00 08    bits_per_pixel: 8
000030  00 00 00 03    bytes_per_line: 3
000034  00 00 00 03    visual_class: 3 (PseudoColor)
000038  00 00 00 00 ×3 red, green and blue masks: unused
000044  00 00 00 08    bits_per_rgb: 8
000048  00 00 01 00    colormap_entries: 256
00004C  00 00 00 06    ncolors: 6 colour map entries follow
000050  00 00 00 03 …  window width 3, height 2, x 0, y 0, border 0

000064  39 39 68 65 6C 70 65 72 73 2E 70 70 6D 00
                       window name: "99helpers.ppm" and a zero byte

000072  00 00 00 00  0000 0000 0000  07 00   colour 0: black
00007E  00 00 00 01  0000 0000 FFFF  07 00   colour 1: blue
00008A  00 00 00 02  FFFF FFFF 0000  07 00   colour 2: yellow
000096  00 00 00 03  FFFF FFFF FFFF  07 00   colour 3: white
0000A2  00 00 00 04  0000 FFFF 0000  07 00   colour 4: green
0000AE  00 00 00 05  FFFF 0000 0000  07 00   colour 5: red

0000BA  05 04 01       top row: red, green, blue
0000BD  02 03 00       bottom row: yellow, white, black
  1. 100 00 00 72

    Header size

    114 bytes: the fixed 100-byte header plus the window name that follows it. The pixels can only be found by reading this first.

  2. 200 00 00 07

    File version

    Always 7 for X11 dumps. There's no signature at the start of an XWD file, so readers use this field to check what they've been given; ImageMagick refuses any other value.

  3. 300 00 00 02

    Pixmap format

    2 is ZPixmap: each pixel's bits are stored together. The other values are XYBitmap (0) and XYPixmap (1), where the image is stored one bit plane at a time; xwd -xy writes that form.

  4. 400 00 00 01

    Byte order

    How multi-byte pixels are stored: 1 is MSBFirst (big-endian), 0 is LSBFirst. It describes the pixel data only; the header itself is always big-endian.

  5. 500 00 00 08 … 00 00 00 03

    Pixel layout

    8 bits per pixel, rows padded to a multiple of 8 bits, and bytes_per_line 3: the distance in bytes from one row to the next. Readers must step by this value, not by width × bytes per pixel, because rows can be padded.

  6. 600 00 00 03 (visual_class)

    Visual class

    3 is PseudoColor: each pixel is an index into a colour map. A TrueColor (4) dump holds the colour itself, split by the red, green and blue masks.

  7. 700 00 00 06 (ncolors)

    Colour map size

    6 colour map entries follow the window name. Then come five fields about the window that was dumped: its size, position and border width.

  8. 8"99helpers.ppm"

    Window name

    The title of the window, ending with a zero byte. xwd stores the real window title; Netpbm puts the input file name here.

  9. 900 00 00 05 FFFF 0000 0000 07 00

    A colour map entry

    12 bytes: the pixel value (5), then red, green and blue as 16-bit numbers (FFFF 0000 0000 is red), a flags byte (07: red, green and blue are all set) and a padding byte.

  10. 1005 04 01

    The pixels

    Top row first, one byte per pixel: index 5 (red), 4 (green), 1 (blue). Then the bottom row: yellow, white, black. No compression and no end marker.

Under the hood

How an XWD file is laid out

PartSizeWhat it holds
Header100 bytes25 numbers: version, format, depth, size, byte and bit order, padding, visual class, colour masks, colour map size, window geometry
Window nameheader_size − 100 bytesThe window's title, ending with a zero byte
Colour mapncolors × 12 bytesPixel value, 16-bit red, green and blue, flags
Pixelsbytes_per_line × height (× depth for XYPixmap)The image, top row first

The definition is a C header, XWDFile.h, which defines XWD_FILE_VERSION as 7 and the header as XWDFileHeader. The header is always big-endian, whatever the machine; the pixel data stays in the server's own order, recorded in byte_order. Readers have to honour every field: depth, bits per pixel, row padding, byte order and the masks all vary between displays.

Visual classes

X describes how pixel values become colours with a visual class: StaticGray (0), GrayScale (1), StaticColor (2), PseudoColor (3), TrueColor (4) and DirectColor (5). Classes 0 to 3 use a colour map; TrueColor and DirectColor pack red, green and blue into the pixel, located by the three mask fields. A dump from a typical modern display is TrueColor with a depth of 24, usually stored as 32 bits per pixel.

How to

Taking and viewing a dump with xwd and xwud

  • xwd -out window.xwd: the pointer changes; click a window to dump it. The keyboard bell rings once when the dump starts and twice when it's done.
  • xwd -root -out screen.xwd: the whole screen, without clicking.
  • xwd -frame -out window.xwd: include the window manager's frame around the clicked window.
  • xwd -name "Terminal" or xwd -id 0x1e00007: pick a window by its title or ID.
  • xwd -screen: read the image from the root window, so menus and pop-ups that are separate windows are captured too.
  • xwud -in window.xwd: show a dump in a window. Click or press q to close it. xwud -dumpheader -in window.xwd prints the header fields instead of showing the image.

Without -out, xwd writes to standard output, which makes it easy to pipe into a converter: xwd -root | magick xwd:- screenshot.png.

Comparison

XWD vs PNG, BMP and PNM

XWDPNGBMPPNM
CompressionNoneLossless (Deflate)Usually noneNone
Pixel layoutAs the X server stored it, described by the headerFixed by the specificationFixed, bottom-up rowsFixed, top-down rows
Portable between machinesReaders must handle byte order and masksYesYesYes
Extra dataWindow name and geometryText, Exif, colour profilesColour profilesComments
Opens in a browserNoYesYesNo

XWD is a capture format, not a storage format. Convert screenshots to PNG, which keeps every pixel and is far smaller; use PNM as a go-between if you're processing them with Netpbm tools.

How to

How to open and convert an XWD file

  • On Linux and other X11 systems: xwud -in file.xwd shows it; GIMP opens and exports XWD.
  • On Windows and macOS: GIMP and XnView open XWD files. The built-in photo viewers don't.
  • With ImageMagick: magick file.xwd file.png (convert in ImageMagick 6), or magick file.png file.xwd to make one.
  • With Netpbm: xwdtopnm file.xwd > file.ppm, and pnmtoxwd the other way.
  • With FFmpeg: ffmpeg -i file.xwd file.png. FFmpeg reads and writes XWD.
  • In a browser: no browser displays XWD. Convert it first.

Troubleshooting

Common XWD problems

  • ImageMagick says "file format version mismatch" or "improper image header". The file isn't an X11 dump (file version 7), the header is damaged, or it's not an XWD file at all: there's no signature to check, so a wrong extension goes unnoticed until a reader looks at the version field.
  • Colours are swapped or noisy. The reader ignored byte_order or the colour masks, often with a dump made on a machine with the other byte order. Use a mature converter such as ImageMagick, Netpbm or FFmpeg rather than a hand-written reader.
  • The image slants diagonally. A reader assumed rows are width × bytes per pixel long instead of using bytes_per_line.
  • Parts of the window are black or show another window. When a window is covered by another one and the server keeps no copy of the hidden part, X doesn't define what XGetImage returns there. Bring the window to the front, or dump with -root or -screen.
  • The file is huge. XWD stores every pixel uncompressed, and a 24-bit display usually uses 4 bytes per pixel: a 1920 × 1080 screen is about 8.3 MB. Convert to PNG.

Window titles travel with the file

The header keeps the dumped window's title, which can include a document name, a web page title or an email subject. Like any screenshot, the pixels show whatever was on screen. Check both before sharing a dump, or convert it to PNG: ImageMagick doesn't carry the window name into the PNG.

Sample files

There are no sample XWD files on this page yet. To make one for testing, run xwd -out test.xwd on an X11 desktop and click a window, or convert any image with ImageMagick (magick input.png output.xwd) or Netpbm (pnmtoxwd input.ppm > output.xwd).

Put it online

Have an XWD file? Give it a link.

Drop an XWD dump on 99helpers and it gets its own web address. Browsers can't display XWD, so anyone who opens the link downloads the file; to have the screenshot seen in the browser, upload a PNG copy next to it.

Questions

XWD files, frequently asked

What is an XWD file?

An X Window Dump: a screenshot of a window or screen taken with the xwd tool on the X Window System. It's a header describing the display, the window name, a colour map and the uncompressed pixels.

How do I open an XWD file?

On Linux, xwud -in file.xwd. On any system, GIMP or XnView, or convert it with ImageMagick (magick file.xwd file.png).

How do I convert XWD to PNG?

Run magick file.xwd file.png, ffmpeg -i file.xwd file.png, or xwdtopnm file.xwd | pnmtopng > file.png. Nothing is lost.

How do I take a screenshot with xwd?

Run xwd -out shot.xwd and click the window, or xwd -root -out shot.xwd for the whole screen. Pipe it straight to PNG with xwd -root | magick xwd:- shot.png.

Why is my XWD file so big?

It isn't compressed, and on most displays each pixel takes 4 bytes. Converting to PNG usually makes a screenshot many times smaller without losing anything.

Is XWD the same as a PNG or BMP?

No. It stores pixels in whatever layout the X server used, described by its header, so readers must handle byte order, depth and colour maps. PNG and BMP have fixed layouts.

Related formats

Other file types explained

Keep going

Related

Sources

Last reviewed 27 October 2026.