Search for a tool
Elias Delta Encoding

Tool for encoding and decoding integers using Elias Delta coding, visualizing the steps, comparing with Elias Gamma, and integrating the binary into your compression data

Results

Elias Delta Encoding -

Tag(s) : Compression, Notation System

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'Elias Delta Encoding' tool for free! Thank you!

Elias Delta Encoding

Elias Delta Decoder






Elias Delta Encoder






Answers to Questions (FAQ)

What is Elias Delta coding? (Definition)

The Elias Delta encoding is an entropy compression algorithm for encoding strictly positive integers ($ n \ge 1 $) in compact binary form.

It is a universal prefix code: no codeword is a prefix of another, allowing for unambiguous decoding without a separator.

It is designed to represent integers without knowing their probability distribution beforehand, using codewords whose length increases approximately as $ \log_2 n + 2\log_2\log_2 n $

How does Elias Delta coding work?

The method involves two steps. First, the user calculates $ L = \lfloor \log_2 n \rfloor $, that is, the position of the most significant bit of $ n $.

The high part is defined as $ H = L + 1 $ (the binary length of $ n $), which is then encoded using Elias Gamma.

The low part corresponds to the $ L $ bits of $ n $ after removing the most significant bit.

Example: For $ n = 10 $
$ L = \lfloor \log_2 10 \rfloor = 3 $, so $ H = 4 $
The low part is $ 10 - 2^3 = 2 $, which is 010 in binary over $ 3 $ bits.

The Delta code is the concatenation of Gamma($ H $) followed by these $ L $ bits.

What are the differences between Elias Delta and Elias Gamma?

Elias Gamma directly encodes $ n $, whereas Elias Delta first encodes the binary length of $ n $, which reduces overhead for large integers.

The length of the Gamma code is $ 2\lfloor \log_2 n \rfloor + 1 $

The length of the Delta code is $ \lfloor \log_2 n \rfloor + 2\lfloor \log_2(\lfloor \log_2 n \rfloor + 1) \rfloor + 1 $

Thus, when $ n $ becomes very large, the dominant term of Delta grows more slowly than that of Gamma, making it more efficient for wide-ranging and highly variable values.

Gamma remains simpler and is often preferable for small integers.

How do you decode an integer encoded in Elias Delta?

To decode, the user begins by decoding the Elias prefix Gamma, which yields $ H $ (the binary length of $ n $).

The user then sets $ L = H - 1 $. They then read the following $ L $ bits, which constitute the lower part. The integer is reconstructed by $ n = 2^L + \text{lower part} $.

Example: If the binary stream begins with Gamma($ 4 $) followed by 010, then $ H = 4 $, so $ L = 3 $, the lower part is $ 2 $, and $ n = 2^3 + 2 = 10 $

When should Elias Delta coding be used?

The user may prefer Elias Delta for:

— index or gap compression in algorithms like LZ77;

— compact storage of identifiers or offsets in databases;

— transmission of packets containing large integers.

For very small integers (typically $ n \le 4 $), Elias Gamma or unary encoding may be more efficient.

If the distribution of integers is known and highly skewed, an adaptive encoding (e.g., Huffman or Golomb-Rice) will generally be superior.

What happens with powers of 2?

If $ n = 2^k $, then $ L = k $ and the low part is $ 0 $. The Delta code is then simply Gamma($ k+1 $) followed by $ k $ zeros.

How to encode 0 using an offset?

Elias Delta is defined only for strictly positive integers ($ n \ge 1 $), because calculating $ \lfloor \log_2 n \rfloor $ is impossible for $ n = 0 $

To include $ 0 $, the user can apply a systematic offset before encoding.

The simplest method is to encode $ n' = n + 1 $ with Elias Delta. Thus: $ n = 0 $ becomes $ n' = 1 $ and is encoded normally; $ n = 1 $ becomes $ n' = 2 $, and so on.

When decoding, the user applies the opposite operation: if Delta returns $ n' $, then the original integer is $ n = n' - 1 $

This transformation is bijective and does not alter the prefix properties of the code.

How to encode negative numbers?

Elias Delta can only encode positive integers. To encode signed integers, the user first applies zigzag encoding, which transforms each relative integer $ x $ into a non-negative integer $ z(x) $ by alternating positives and negatives around zero.

The standard transformation is: $ z(x) = 2|x| $ if $ x < 0 $, $ z(x) = 2x + 1 $ if $ x \ge 0 $

This gives the correspondence: $ 0 \mapsto 1 $, $ -1 \mapsto 2 $, $ 1 \mapsto 3 $, $ -2 \mapsto 4 $, $ 2 \mapsto 5 $, etc.

The user then encodes $ z(x) $ with Elias Delta (possibly offset to include $ 0 $ if necessary). On decoding, the inverse operation reconstructs $ x $:

$ x = \lfloor z/2 \rfloor $ if $ z $ is even (original negative)

$ x = (z - 1)/2 $ if $ z $ is odd (original positive)

Zigzag is particularly suitable for Elias codes because it prevents small negative numbers from producing very large codes, by keeping values close to zero represented by small integers.

Source code

dCode retains ownership of the "Elias Delta Encoding" source code. Any algorithm for the "Elias Delta Encoding" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Elias Delta Encoding" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Elias Delta Encoding" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.

Cite dCode

The content of the page "Elias Delta Encoding" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).

Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).

To cite dCode.fr on another website, use the link: https://www.dcode.fr/elias-delta-encoding

In a scientific article or book, the recommended bibliographic citation is: Elias Delta Encoding on dCode.fr [online website], retrieved on 2026-02-06, https://www.dcode.fr/elias-delta-encoding

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'Elias Delta Encoding' tool for free! Thank you!


https://www.dcode.fr/elias-delta-encoding
© 2026 dCode — The ultimate collection of tools for games, math, and puzzles.
 
Feedback