ICO (Windows Icon)
| Full name | Windows Icon (ICO); Windows Cursor (CUR) is the same container |
|---|---|
| Extensions | .ico (icon), .cur (cursor) |
| MIME type | image/vnd.microsoft.icon (registered), image/x-icon (common) |
| Type | container of raster images (BMP/DIB or PNG), lossless |
| Starts with | 00 00 01 00 (ICO), 00 00 02 00 (CUR) |
| Specification | no formal spec; Microsoft documents it in Icons (Win32) |
| Maintained by | Microsoft |
| License | open, no royalties |
An ICO file is a small directory of images: the same icon drawn at several sizes and color depths, for example 16x16, 32x32, 48x48 and 256x256. Windows picks the entry that best matches the size it needs (taskbar, Explorer, title bar, high-DPI screens). Each entry is either a BMP-style bitmap with a transparency mask or a complete PNG file.
ICO is used for Windows application and file icons and for favicon.ico, the site icon browsers request from the root of a web server. A CUR file is the same structure with type 2 and a hotspot (the click point) per entry instead of planes and bit depth. Animated cursors (.ani) are a different, RIFF-based format that contains ICO/CUR frames.
When to use ICO#
- Use for Windows program icons (
.exeresources), shortcut and file-type icons, and static mouse cursors (.cur). - Use for
favicon.icowhen you want one file that every browser and tool finds without any<link>tag. - Avoid as a general image format: it’s limited to 256x256 per entry and has no metadata.
- Avoid for modern web icons when you control the HTML: a PNG or SVG favicon with
<link rel="icon">plus anapple-touch-iconPNG covers current browsers.
File structure#
An ICO file has 3 parts: a 6-byte ICONDIR header, one 16-byte ICONDIRENTRY per image, and the image data. All integers are little-endian.
00 00 reserved, must be 0
01 00 type: 1 = icon (ICO), 2 = cursor (CUR)
01 00 number of images: 1
-- ICONDIRENTRY #1 --
20 width: 32 (0 means 256)
20 height: 32 (0 means 256)
00 colors in palette: 0 (no palette)
00 reserved
01 00 ICO: color planes (0 or 1) CUR: hotspot X
20 00 ICO: bits per pixel: 32 CUR: hotspot Y
A8 10 00 00 size of image data: 4264 bytes
16 00 00 00 offset of image data: 22
-- image data at offset 22 --
28 00 00 00 BITMAPINFOHEADER size: 40
20 00 00 00 width: 32
40 00 00 00 height: 64 (2 x 32: color bitmap + AND mask)
01 00 20 00 planes 1, 32 bits per pixel
00 00 00 00 ... compression BI_RGB, then 32x32x4 pixel bytes and a 32x32 1-bit mask
ICONDIR#
| Offset | Size | Field | Value |
|---|---|---|---|
| 0 | 2 | Reserved | 0 |
| 2 | 2 | Type | 1 = icon, 2 = cursor |
| 4 | 2 | Count | number of images |
ICONDIRENTRY#
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 1 | Width | pixels, 0 = 256 |
| 1 | 1 | Height | pixels, 0 = 256 |
| 2 | 1 | ColorCount | palette entries, 0 if more than 256 colors or no palette |
| 3 | 1 | Reserved | 0 |
| 4 | 2 | Planes / Hotspot X | ICO: 0 or 1. CUR: hotspot X from the left |
| 6 | 2 | BitCount / Hotspot Y | ICO: bits per pixel. CUR: hotspot Y from the top |
| 8 | 4 | BytesInRes | size of the image data |
| 12 | 4 | ImageOffset | offset of the image data from the start of the file |
The directory values are hints. Decoders should trust the size and bit depth in the image data itself, because many tools write 0 for planes and bit count.
Image data: BMP or PNG#
Each entry’s data is one of 2 things:
- PNG: a complete PNG file, starting with
89 50 4E 47. Supported since Windows Vista. Use 32-bit RGBA. Microsoft recommends PNG only for 256x256 entries, where it saves the most space. - BMP/DIB: a BMP without the 14-byte
BITMAPFILEHEADER: aBITMAPINFOHEADER(40 bytes), a palette for 1, 4 and 8 bpp, the color (XOR) bitmap and a 1-bit AND mask. The header’s height is twice the icon height because it covers both bitmaps. Rows are stored bottom-up and padded to 4 bytes.
The AND mask marks transparent pixels (1 = transparent) for 1-24 bpp images. 32 bpp entries carry an 8-bit alpha channel, and the mask is still present for old software.
Icons in EXE and DLL files#
Inside a Windows executable the icon is split into resources: one RT_GROUP_ICON resource holds the directory and each image is a separate RT_ICON resource. The group entry (GRPICONDIRENTRY) is 14 bytes: it has a 2-byte resource ID where the file format has the 4-byte offset. Tools that “extract icons” from an EXE rebuild an ICO file from these resources.
Sizes to include#
| Use | Sizes |
|---|---|
| Windows application icon | 16, 24, 32, 48, 64, 256 (add 20, 40, 96 for exact high-DPI scaling) |
favicon.ico |
16, 32, 48 |
Cursor (.cur) |
32 (add 48, 64, 96, 128 for high-DPI pointers) |
Draw the small sizes by hand or at least sharpen them: a 256x256 icon scaled down to 16x16 is often blurry. Store 256x256 as PNG and the smaller sizes as 32-bit BMP for the best compatibility.
Specifications and documentation#
- Icons (Win32 technical article) (Microsoft):
ICONDIR,ICONDIRENTRY, image data and icon resources - About Cursors (Microsoft): cursors and hotspots
- Icons in the Windows UX guidelines (Microsoft): which sizes to draw
- PNG images in icons, and why only for 256x256 (The Old New Thing)
- image/vnd.microsoft.icon (IANA media type registration)
- ICO file format on Wikipedia
Software that opens ICO files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; shows the ICO image | |||
| Windows File Explorer and Photos | ✓ | view | built into Windows; Explorer shows .ico and .cur files as their own thumbnails | |||
| Web browsers | ✓ | ✓ | ✓ | ✓ | view | Chrome, Edge, Firefox, Safari; used for favicon.ico. Also on Android and iOS |
| macOS Preview | ✓ | view | built into macOS; shows every size in the sidebar | |||
| GIMP | ✓ | ✓ | ✓ | view, edit, create, convert | free, open source; each layer becomes one icon size on export | |
| Greenfish Icon Editor Pro | ✓ | ✓ | view, edit, create, convert | free icon and cursor editor | ||
| IcoFX | ✓ | view, edit, create, convert | commercial icon editor; extracts icons from EXE and DLL | |||
| IrfanView | ✓ | view, convert | free for non-commercial use | |||
| XnView MP | ✓ | ✓ | ✓ | view, convert | free for private use | |
| ImageMagick | ✓ | ✓ | ✓ | convert, create | command line, open source; magick in.png -define icon:auto-resize=256,48,32,16 out.ico | |
| Photopea | ✓ | view, edit | free, runs in the browser | |||
| RealFaviconGenerator | ✓ | create | builds favicon.ico and PNG icons from one image |
Libraries#
Open-source libraries that read and write ICO. See all ICO libraries for a comparison.
| C/C++ | Magick++ |
|---|---|
| C# | ImageSharp, Magick.NET, System.Drawing.Icon |
| Java | TwelveMonkeys |
| Go | go-ico |
| Python | Pillow |
| Ruby | MiniMagick |
| Rust | ico, image |
| PHP | Imagick |