# Packing Ternary Numbers into 8-Bit Bytes for Efficient LLM Weights

Original title: How to pack ternary numbers in 8-bit bytes

> Hacker News story 48912812 · language: en · submitted 2026-07-14
> Web version: https://zeli.app/story/48912812
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 107 · by [JoshTriplett](<https://news.ycombinator.com/user?id=JoshTriplett>) · 💬 50
[original](<https://compilade.net/blog/ternary-packing>) · [HN discussion](<https://news.ycombinator.com/item?id=48912812>)

## Summary

I explored packing ternary digits, or trits, into 8-bit bytes to optimize storage for BitNet b1.58 weights. By fitting five trits into a byte, I achieved 99% efficiency. This method uses fixed-point multiplication for fast SIMD-friendly unpacking, avoiding slow division operations. The technique is now integrated into llama.cpp for TriLMs and BitNet b1.58, enabling faster processing on AVX2 and ARM NEON hardware.

## Key quote

> Would it be nice if instead of extracting the least significant digit with modulo, we could extract the most significant digit with a multiplication?

## HN discussion (50 comments)

### [JoshTriplett](<https://news.ycombinator.com/item?id=48912951>)

> It's impressive how close to optimal this is.
>
> You can beat the efficiency of 5 trits in 8 bits (1.6) with as few as 17 trits in 27 bits (~1.588), but once you account for rounding up to a whole number of bytes for practical reasons, then beating the efficiency requires going to at least 111 trits in 176 bits (~1.586), or perhaps more practically for fast unpacking, 161 trits in 256 bits (~1.59).
>
> At that level, even if you have, say, 27B trits, the more efficient encodings would save something like 38-45MB (theoretical limit ~48MB), likely at the cost of some slowdown.

### [lioeters](<https://news.ycombinator.com/item?id=48991394>)

> Amusing that the link to an article on ternary numbers was posted by Mr Triplett. (:
>
> The article is well-written and illustrated. The technique described is used in llama.cpp for running language models like BitNet b1.58 whose weights are stored as ternary types.
>
> \> ..in which every single parameter (or weight) of the LLM is ternary {-1, 0, 1}
>
> \> significantly more cost-effective in terms of latency, memory, throughput, and energy consumption
>
> The original paper on this technique was published in Feb 2024. (Also linked from the article)
>
> The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits - https://arxiv.org/abs/2402.17764
>
> However, since then there have only been a few other models using ternary weights. I get the impression that there are factors not considered in the paper which make it less practical than it seemed.

### [JKCalhoun](<https://news.ycombinator.com/item?id=48992394>)

> Despite my ignorance on what would be involved, I like to fantasize that companies like Apple (who own their own chip design and hardware) can put these ternary pack/unpack operations in hardware with a single instruction for each (and also instructions for performing the various matrix convolutions using ternary numbers) so that we can get on-device LLMs.
>
> I suppose with the recent quantized Bonsai models we're already seeing on-device LLMs for phones and the like… But I (again, forgive my ignorance) assume that there is an order of magnitude or more in performance sitting out there if we get custom hardware instructions.

### [Diggsey](<https://news.ycombinator.com/item?id=48990915>)

> How does this packing/unpacking scheme compare to just using a lookup table?

### [jjgreen](<https://news.ycombinator.com/item?id=48989768>)

> Possible application: https://thedailywtf.com/articles/What_Is_Truth_0x3f_

---

## Cite

- Page: https://zeli.app/story/48912812
- Date: 2026-07-14
- Source: compilade.net (https://compilade.net/blog/ternary-packing)
- Hacker News: https://news.ycombinator.com/item?id=48912812

## Other languages

- zh: https://zeli.app/zh/story/48912812 · markdown: https://zeli.app/zh/story/48912812.md
- ja: https://zeli.app/ja/story/48912812 · markdown: https://zeli.app/ja/story/48912812.md
- ko: https://zeli.app/ko/story/48912812 · markdown: https://zeli.app/ko/story/48912812.md
- de: https://zeli.app/de/story/48912812 · markdown: https://zeli.app/de/story/48912812.md
- es: https://zeli.app/es/story/48912812 · markdown: https://zeli.app/es/story/48912812.md
