ElfHash explained in plain terms means understanding the tiny hash that finds symbols inside Linux programs, a design from the 1980s that turns a name into a bucket number with a shift, an add and a fold. The central question is why a linker would trust such a small hash when stronger ones exist, and the answer is that symbol lookup only needs speed and a decent spread, so ElfHash gives the dynamic linker both in a handful of instructions, and that economy is the whole point of the design.
ElfHash is the System V version of Peter J. Weinberger’s PJW hash, published in the System V Application Binary Interface for ELF object files. It turns a symbol name into a 32-bit value by walking its bytes one at a time, and it is built on the idea that a hash can be tiny when its job is only to pick a bucket, which means the design trades strength for simplicity, and that trade is what makes it unlike the hashes of its era.
This article explains what ElfHash is, how it works, and where it runs in the real world.
Key takeaways
- ElfHash is the System V form of Weinberger’s PJW hash.
- It returns a 32-bit value, but only 28 bits ever vary.
- It shifts left by four, adds a byte, then folds the top nibble.
- It indexes the symbol hash table in ELF files.
- Linux later replaced it with the faster GNU hash.
What ElfHash is
ElfHash is a hash that turns a name into a bucket number with a loop of three steps, and that smallness is what makes it unusual among hashes. Each byte shifts the running value left by four bits and is added in, which means the hash grows as the name grows, and because the shift is small, short names stay close together while long names spread out.
Its signature feature is the fold. Most hashes let high bits fall away, but ElfHash catches the top four bits before they vanish and xors them back into the middle, which means every character keeps some influence on the result, and because the fold happens on every byte, no character is ever lost entirely.
The design was a reaction to the linker’s need for speed. A dynamic linker looks up thousands of symbols when a program starts, so Weinberger’s hash had to be cheap enough to run on every lookup, because a slow hash would slow every program launch, and that practicality is what made ElfHash worth standardising.
It became one of the best-known tiny hashes in the world, and it is named in every discussion of the field. ElfHash lives in the .hash section of ELF files, it is implemented in libelf as elf_hash, and it is still the first example students meet when they learn that a hash can be four lines long, which means the design survives as a lesson even though Linux moved on.
Its most famous property is its 28-bit output. The final step clears the top four bits, so the value never exceeds 0x0FFFFFFF, which means the hash has only 268 million possible values, and because that range is small, collisions are easy to build, which is why nobody uses ElfHash for security.
Our guide to hashing explains what a hash function does in the first place, and our guide to MurmurHash explains the faster hash that replaced tiny designs like this one in tables.
How ElfHash works
Everything starts with zero, which is the initial hash value. ElfHash sets its running value to nothing before reading any input, which means the empty string hashes to zero, and because the start is fixed, the same name always gives the same hash.
Each step begins with a byte of the name, which is added after a shift. ElfHash takes the next character, shifts the running value left by four bits and adds the byte in, which means fresh data arrives at every step, and because the shift is only four bits, the value grows slowly enough to stay useful.
The fold is what makes the design work as a whole. After the add, ElfHash checks the top four bits, and if any are set it xors them down into bits 24 to 27, which means the high bits are recycled instead of lost, and because the fold runs on every byte, long names keep their early characters in the mix.
The mask spreads the effect further. ElfHash then clears the top four bits with an AND, which means the value never grows past 28 bits, and because the mask runs after the fold, the recycled bits are the only trace the top nibble leaves behind.
The bucket is what turns the hash into a lookup. The dynamic linker takes the hash modulo the number of buckets, which means the value picks one chain in the table, and because the chains hold the symbols, the linker walks only a short list instead of the whole table.
The result comes from the final value, read out as a 28-bit number. ElfHash outputs the running value directly as the hash, which means the result is a fixed size whatever the input, and that size is exactly what a symbol table needs for its bucket index.

Comparing ElfHash with other string hashes
ElfHash is one of several tiny hashes built for tables, and each was built with a different emphasis. djb2 is the multiply-and-add hash that became the default in many codebases, FNV-1a is the xor-and-multiply hash built for checksums, and ElfHash is the one built for symbol tables, while each approach trades something for something else.
The table below sets out the main contrasts between the leading approaches.
| Aspect | ElfHash | djb2 | FNV-1a |
|---|---|---|---|
| Output size | 28 bits used | 32 bits | 32 or 64 bits |
| Core step | Shift, add, fold | Multiply by 33, add | Xor byte, multiply by prime |
| Seeded | No | No | No, fixed offset basis |
| Year | 1986 | 1991 | 1991 |
| Best for | Symbol tables | General string hashing | Checksums and tables |
The practical result is that ElfHash is the right choice for symbol tables, djb2 suits general string hashing, and FNV-1a fits checksums and tables instead.
Where ElfHash is used
Dynamic linkers use it to find symbols. The ELF .hash section stores the hash of every exported symbol, because a program that loads a library must resolve its symbols fast, and that lookup is the reason ElfHash ran at the heart of every Linux start-up.
Compilers use it to teach hashing. Courses introduce ElfHash when they explain that a hash can be a few lines long, because it is the clearest case of the idea in a real format, and a student who understands ElfHash understands why a bucket index is enough.
Toolchains use it to read old binaries. A linker or a debugger that opens an older ELF file still meets the .hash section, because the format kept it for compatibility, and that history is the reason ElfHash still appears in tools today.
Libraries use it through libelf. The elf_hash function in libelf computes the value for any string, because tools need the same hash the linker used, and that shared code is the reason every implementation agrees.
Teaching uses it as the fold example. Courses introduce ElfHash when they explain that high bits can be recycled instead of dropped, because it is the clearest case of the idea in a real hash, and a student who understands the fold understands why 28 bits can still be useful.
Strengths and limits
The greatest strength of ElfHash is its size. A hash that fits in a few instructions runs on every symbol lookup for free, and that strength is real, measured in the decades it served Linux and confirmed by the linkers that relied on it.
It is also a strength that the design is trivial to explain. A shift, an add and a fold is easy to describe, and that simplicity is worth more than cleverness in a field where a hash nobody can audit is a hash nobody trusts.
The limits are real, though, and the biggest is the 28-bit output. A hash with only 268 million values collides easily, which means it must never guard anything an attacker can influence, and a system that needs a stronger hash must use a modern design instead.
ElfHash checklist
- Use ElfHash for ELF symbol tables, never for security.
- Remember it is Weinberger’s PJW hash in System V form.
- Note only 28 bits of the 32-bit output ever vary.
- Compare it with djb2 to see two kinds of tiny hash.
- Study the fold, which recycles the top nibble.
- Check the bucket count, which sets the table size.
- Keep real digests behind standard hashes for signatures.
- Read the System V ABI to see how the .hash section works.
- Choose the GNU hash when a linker needs more speed.
Frequently asked questions
What is ElfHash in simple terms?
It is a tiny 32-bit string hash from the System V ABI that turns a symbol name into a bucket number with a shift, an add and a fold.
Who designed ElfHash?
Peter J. Weinberger, whose PJW hash became the ELF hash in the System V Application Binary Interface.
How is ElfHash different from djb2?
Both are tiny string hashes, but ElfHash folds its top bits back in while djb2 multiplies by 33 and adds each byte.
Is ElfHash still secure?
No, it has only 28 useful bits and collisions are easy to build, so it must never guard secrets or signatures.
Where is ElfHash used?
In the .hash section of ELF files, in dynamic linkers, in libelf, and in teaching about hash tables.
When should I use ElfHash?
When you read or write ELF symbol tables, when you study tiny hashes, or when you want the hash behind Linux symbol lookup.
The bottom line
ElfHash explained in one line is this: the symbol-table hash, a 1980s design of shifts and folds that indexed every Linux library and taught the field that a hash can be four lines long.
It is proof that small can be enough, and the reason it still matters is that every tiny hash designed since has been judged partly by the lesson ElfHash taught.
This article is general information about how ElfHash works, not advice about choosing encryption for a particular device or system.







