Telegram inline keyboard callback data: why the 64-byte limit breaks bots
What inline keyboards actually do
An inline keyboard is the row of buttons attached directly under a bot message. Tap one and Telegram sends a callback query back to your bot instead of posting a new message in the chat. That’s the whole appeal: menus, pagination, confirm/cancel prompts, and settings toggles that don’t clutter the conversation with extra text.
The button itself is simple. It has a label the user sees, and it carries one of a handful of payload types behind it: a URL, a switch_inline_query, a web_app reference, or the one almost every bot ends up using, callback_data. That field is where you put whatever your bot needs to know when the button gets pressed, like “which item” or “which page” or “confirm this action.”
And that field is where people get stuck, because callback_data has a hard limit that isn’t obvious until you hit it.
The limit nobody reads about until they hit it
callback_data is capped at 1 to 64 bytes. Not characters, bytes. If you’re using anything outside plain ASCII, that ceiling drops fast, since UTF-8 multi-byte characters eat more of the budget per character.
Try to send a button with more than 64 bytes in callback_data and the Bot API rejects the request outright. You don’t get a partial send or a silent truncation. It just fails, and if you’re not checking the response you’ll see it as a mysterious “button didn’t show up” bug days later.
64 bytes sounds small because it is small. It’s roughly one short sentence, or a UUID plus a couple of extra fields, or a small JSON object with two or three keys. People who build their first inline keyboard usually reach for something like this without thinking about it:
{"action":"delete","item_id":"a1b2c3d4-e5f6-...","user_id":123456789}
That’s well over 64 bytes before you’ve added anything else. It works fine in testing with short fake IDs, then breaks the first time it runs against a real UUID or a longer identifier, and the failure shows up as a button that silently never gets created.
Why the limit exists
Telegram isn’t storing your callback_data anywhere persistent on their end for you to query later. It rides along with the message metadata and gets echoed back verbatim when someone taps the button, potentially much later, after the bot has restarted, after the process has moved to a different server, after weeks have passed. The tighter the payload, the cheaper that is to carry around indefinitely on every message that has buttons. A 64-byte cap keeps that overhead predictable regardless of how many keyboards a bot has ever sent.
The practical result is that callback_data was never meant to hold your data. It was meant to hold a reference to your data.
The fix: store state, not data
The pattern that gets you out of this is the same one you’d use for any system with a tight payload limit: keep the full state on your side, and put only a short opaque token in the button.
Instead of encoding {"action":"delete","item_id":"a1b2c3d4-..."}, you generate a short key, say del:8f2a91, store the actual action and item_id in your own database or cache keyed by that string, and put only the short key in callback_data. When the callback query comes in, you look up 8f2a91, pull the real payload, and act on it.
This has knock-on benefits beyond just fitting in 64 bytes:
- You can expire or invalidate a button’s meaning without editing the message. If a token isn’t found, your bot can just answer the callback query with “this action expired” instead of silently failing.
- You’re not leaking internal IDs or structure into something that’s technically visible to anyone inspecting the client, or logged by any middleware sitting between your bot and Telegram.
- You avoid re-parsing and re-validating a payload blob on every tap. A key lookup is cheaper and easier to reason about than untrusted JSON coming back from a button.
The lookup store doesn’t need to be fancy. A table with a short random key, the intended action, and a created_at column you periodically sweep is enough for most bots. If you’re running something with high tap volume, an in-memory cache in front of that table saves you a database round trip per callback, but that’s a scaling decision, not a requirement to get started.
Squeezing a bit more into 64 bytes when you don’t want a lookup table
Sometimes a lookup store is more infrastructure than a small bot needs, and you’d rather encode state directly in the button. A few things buy you room without changing your architecture:
Use short field names and positional data instead of JSON. d:1234:2 fits far more information in the same byte count than {"action":"delete","id":1234,"page":2} because you’re not paying for quote characters, colons, and key names on every button.
Use base36 or base62 for numeric IDs instead of decimal. A database ID that’s 8 decimal digits shrinks noticeably when represented in base62, since you’re packing more value per character.
Drop anything you can derive instead of storing it. If the bot already knows which chat and which message the callback came from, you don’t need chat_id or message_id in the payload. The callback query object hands you both automatically.
These tricks stretch 64 bytes further, but they don’t remove the ceiling. Once your state genuinely needs more than a short reference, a lookup table stops being optional.
Two behaviors that trip people up after the limit is solved
Even once callback_data fits, there are two adjacent things worth knowing.
First, answerCallbackQuery. When a user taps a button, the client shows a brief loading state on it until your bot calls answerCallbackQuery, or until the client gives up waiting and the loading indicator just fades. If your bot never calls it, buttons will feel unresponsive even though the callback was received and processed correctly on your end. It’s a one-line call, and it’s easy to forget when you’re focused on the business logic of what the button does.
Second, edit frequency. If your keyboard changes based on state, pagination is the classic example, you’ll be calling editMessageReplyMarkup or editMessageText repeatedly. Telegram’s documented guidance is to avoid sending more than one message per second into the same chat, and that same restraint applies to edits. A bot that redraws a keyboard on every tap in a fast back-and-forth can start hitting rate limiting if it’s not pacing those edits, which shows up as delayed or dropped updates rather than a clean error.
Where this connects to hosting and infra
We run managed Telegram hosting and proxy infrastructure, so the part of this that lands on our side of the fence is usually the lookup store, not the Bot API call itself. A bot that’s doing the token-and-database pattern correctly is making an extra read on every button tap, and if that store is on the same box as everything else with no indexing on the key column, that’s the kind of thing that looks fine at low volume and turns into latency once a bot has real traffic. Index the key, expire old rows, and keep the table small. It’s a minor operational detail, but it’s the difference between callback taps feeling instant and feeling laggy once a bot has more than a handful of active users.
None of this touches account safety directly, inline keyboards are a bot-side feature and don’t involve account credentials or sessions, but the general instinct of not putting more than you need into a payload that travels back and forth with the client is a good habit regardless of what you’re building.
If you’re setting up the hosting and proxy side of a Telegram bot and want it done properly from the start, take a look at what we run.
Get new guides and videos first — join the Telegram channel.