Databases 5 min read

Understanding MySQL INT Display Width and ZEROFILL

This article explains that the numeric value in MySQL INT definitions (e.g., int(1) or int(10)) does not limit the column's range, demonstrates inserting the maximum unsigned value, and shows how ZEROFILL combined with a display width pads numbers with leading zeros.

Top Architect
Top Architect
Top Architect
Understanding MySQL INT Display Width and ZEROFILL

When adding a user_id column, the author initially used int(1) and was told the size might be insufficient; however, the display width in MySQL does not affect the actual range of the integer type.

In MySQL an INT occupies 4 bytes, so an unsigned INT can store values up to 2^32‑1 (= 4294967295). The author created a table with int(1) unsigned and successfully inserted the maximum value, proving that int(1) , int(2) … int(10) all have the same range.

CREATE TABLE `user` (
  `id` int(1) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
mysql> INSERT INTO `user` (`id`) VALUES (4294967295);
Query OK, 1 row affected (0.00 sec)

The numeric argument only influences the display width when used together with the ZEROFILL attribute. The author then created a table with int(4) unsigned ZEROFILL , inserted several values, and queried the table to show the padded output.

CREATE TABLE `user` (
  `id` int(4) unsigned ZEROFILL NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
INSERT INTO `user` (`id`) VALUES (1),(10),(100),(1000);
Query OK, 4 rows affected (0.00 sec)
SELECT * FROM user;
+------+ 
| id   |
+------+ 
| 0001 |
| 0010 |
| 0100 |
| 1000 |
+------+ 
4 rows in set (0.00 sec)

This demonstrates that ZEROFILL pads numbers to the specified display width, while the width itself does not constrain the stored value; the underlying storage remains the same.

In summary, the number in INT(n) does not represent the column’s capacity; only when combined with ZEROFILL does the display width affect how numbers are presented, useful for fixed‑length identifiers.

SQLDatabaseMySQLintZEROFILLdisplay width
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.