🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 43 (from laksa096)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
11 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.4 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/
Last Crawled2026-04-14 09:11:41 (11 days ago)
First Indexed2019-04-19 17:06:43 (7 years ago)
HTTP Status Code200
Content
Meta TitleWhy hash tables should use a prime-number size — Quick Math Intuitions
Meta DescriptionWhy should hash tables have a prime number for its size? The best size for a hash table has to do with the fact that computers handle data in binary form.
Meta Canonicalnull
Boilerpipe Text
I read in several books and online pages that hash tables should use a prime number for the size. Nobody really justified this statement properly. Here’s my attempt! I believe that it just has to do with the fact that computers work with in base 2. Just think at how the same thing works for base 10: 8 % 10 = 8 18 % 10 = 8 87865378 % 10 = 8 2387762348 % 10 = 8 It doesn’t matter what the number is: as long as it ends with 8, its modulo 10 will be 8. You could pick a huge power of 10 as modulo operator, such as 10^k (with k > 10, let’s say), but you would need a huge table to store the values the hash function is still pretty stupid: it just trims the number retaining only the first k digits starting from the right. However, if you pick a different number as modulo operator, such as 12, then things are different: 8 % 12 = 8 18 % 12 = 6 87865378 % 12 = 10 2387762348 % 12 = 8 We still have a collision, but the pattern becomes more complicated, and the collision is just due to the fact that 12 is still a small number. Picking a big enough, non-power-of-two number will make sure the hash function really is a function of all the input bits, rather than a subset of them. For example, with 367: 8 % 367 = 8 18 % 367 = 18 87865378 % 367 = 73 2387762348 % 367 = 240 What is worth nothing is that there may be a pattern even with modulo 367, but it would be way less trivial than with modulo 10 (or with modulo 2 in binary). We don’t really need a prime number , just having a big non-power of two is enough. Having a prime number, obviously, is just a guaranteed way of satisfying those conditions. Was this Helpful ? yes     no Post navigation
Markdown
[Skip to content](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/#primary) [Quick Math Intuitions](https://quickmathintuitions.org/) Sharing quick intuitions for math ideas [Computer science](https://quickmathintuitions.org/category/computer-science/) # Why hash tables should use a prime-number size [Stefano Ottolenghi](https://quickmathintuitions.org/author/qmi/) [2017-06-012018-03-12](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/) [0](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/#respond) I read in several books and online pages that hash tables should use a prime number for the size. Nobody really justified this statement properly. Here’s my attempt\! *** I believe that it just has to do with the fact that computers work with in base 2. Just think at how the same thing works for base 10: - 8 % 10 = 8 - 18 % 10 = 8 - 87865378 % 10 = 8 - 2387762348 % 10 = 8 It doesn’t matter what the number is: as long as it ends with 8, its modulo 10 will be 8. You could pick a huge power of 10 as modulo operator, such as 10^k (with k \> 10, let’s say), but 1. you would need a huge table to store the values 2. the hash function is still pretty stupid: it just trims the number retaining only the first *k* digits starting from the right. However, if you pick a different number as modulo operator, such as 12, then things are different: - 8 % 12 = 8 - 18 % 12 = 6 - 87865378 % 12 = 10 - 2387762348 % 12 = 8 We still have a collision, but the pattern becomes more complicated, and the collision is just due to the fact that 12 is still a small number. **Picking a big enough, non-power-of-two number will make sure the hash function really is a function of all the input bits, rather than a subset of them.** For example, with 367: - 8 % 367 = 8 - 18 % 367 = 18 - 87865378 % 367 = 73 - 2387762348 % 367 = 240 What is worth nothing is that there may be a pattern even with modulo 367, but it would be way less trivial than with modulo 10 (or with modulo 2 in binary). **We don’t really need a prime number**, just having a big non-power of two is enough. Having a prime number, obviously, is just a guaranteed way of satisfying those conditions. - Was this Helpful ? - [yes](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/) [no](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/) [hash tables](https://quickmathintuitions.org/tag/hash-tables/) ## Post navigation [Metaphysics on geometric distribution in probability theory](https://quickmathintuitions.org/metaphysics-on-geometric-distribution-probability-theory/) [On the meaning of hypothesis and p-value in statistical hypothesis testing](https://quickmathintuitions.org/meaning-hypothesis-p-value-statistical-hypothesis-testing/) ### Leave a Reply [Cancel reply](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/#respond) ![Intuition image](https://quickmathintuitions.org/wp-content/uploads/2016/06/My-aha-moments_float-e1466919792783.jpg) #### Categories - [Algebra](https://quickmathintuitions.org/category/algebra/) - [Analysis](https://quickmathintuitions.org/category/analysis/) - [Computer science](https://quickmathintuitions.org/category/computer-science/) - [Cryptography](https://quickmathintuitions.org/category/cryptography/) - [Finite Element Methods](https://quickmathintuitions.org/category/finite-element-methods/) - [Graph theory](https://quickmathintuitions.org/category/graph-theory/) - [Linear algebra](https://quickmathintuitions.org/category/linear-algebra/) - [Meta](https://quickmathintuitions.org/category/meta/) - [Modeling](https://quickmathintuitions.org/category/modeling/) - [Numerical Analysis](https://quickmathintuitions.org/category/numerical-analysis/) - [Probability](https://quickmathintuitions.org/category/probability/) - [Statistics](https://quickmathintuitions.org/category/statistics/) - [Uncategorized](https://quickmathintuitions.org/category/uncategorized/) #### [![RSS](https://quickmathintuitions.org/wp-includes/images/rss.png)](https://www.thecrowned.org/feeds/all-en.atom.xml) [Blog entries](https://thecrowned.org/) - [On Karpathy's "Software is changing (again)"](https://thecrowned.org/karpathy-software-is-changing) - [How many hours does it take to be pissed at France?](https://thecrowned.org/france-joke) - ["I'm really concerned about Hawai indigenous people's rights"](https://thecrowned.org/philosophy-of-science-class) - [Don't hurt pomegranates](https://thecrowned.org/pomegranate) - [What love tells me](https://thecrowned.org/mahler-love) - [The digital supermarket of human solitude (dating apps)](https://thecrowned.org/dating-apps) - [How Feldenkrais made me the best math teacher](https://thecrowned.org/feldenkrais-math) - [A cybersecurity take on the Swedish postal system](https://thecrowned.org/postnord-drama) - [The dread of teaching pointless math ruins generations](https://thecrowned.org/pointless-math) - [The differences between junior and senior software engineers](https://thecrowned.org/junior-vs-senior-engineers) Copyright © 2026 [Quick Math Intuitions](https://quickmathintuitions.org/ "Quick Math Intuitions"). [Proudly powered by WordPress](https://wordpress.org/) \| Theme: Apace by [ThemezHut](https://themezhut.com/themes/apace/).
Readable Markdown
I read in several books and online pages that hash tables should use a prime number for the size. Nobody really justified this statement properly. Here’s my attempt\! *** I believe that it just has to do with the fact that computers work with in base 2. Just think at how the same thing works for base 10: - 8 % 10 = 8 - 18 % 10 = 8 - 87865378 % 10 = 8 - 2387762348 % 10 = 8 It doesn’t matter what the number is: as long as it ends with 8, its modulo 10 will be 8. You could pick a huge power of 10 as modulo operator, such as 10^k (with k \> 10, let’s say), but 1. you would need a huge table to store the values 2. the hash function is still pretty stupid: it just trims the number retaining only the first *k* digits starting from the right. However, if you pick a different number as modulo operator, such as 12, then things are different: - 8 % 12 = 8 - 18 % 12 = 6 - 87865378 % 12 = 10 - 2387762348 % 12 = 8 We still have a collision, but the pattern becomes more complicated, and the collision is just due to the fact that 12 is still a small number. **Picking a big enough, non-power-of-two number will make sure the hash function really is a function of all the input bits, rather than a subset of them.** For example, with 367: - 8 % 367 = 8 - 18 % 367 = 18 - 87865378 % 367 = 73 - 2387762348 % 367 = 240 What is worth nothing is that there may be a pattern even with modulo 367, but it would be way less trivial than with modulo 10 (or with modulo 2 in binary). **We don’t really need a prime number**, just having a big non-power of two is enough. Having a prime number, obviously, is just a guaranteed way of satisfying those conditions. - Was this Helpful ? - [yes](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/) [no](https://quickmathintuitions.org/why-hash-tables-should-use-prime-number-size/) ## Post navigation
ML Classification
ML Categories
/Computers_and_Electronics
96.1%
/Computers_and_Electronics/Programming
79.2%
Raw JSON
{
    "/Computers_and_Electronics": 961,
    "/Computers_and_Electronics/Programming": 792
}
ML Page Types
/Article
99.9%
/Article/Tutorial_or_Guide
81.4%
Raw JSON
{
    "/Article": 999,
    "/Article/Tutorial_or_Guide": 814
}
ML Intent Types
Informational
99.9%
Raw JSON
{
    "Informational": 999
}
Content Metadata
Languageen-us
AuthorStefano Ottolenghi
Publish Time2017-06-01 08:57:36 (8 years ago)
Original Publish Time2017-06-01 08:57:36 (8 years ago)
RepublishedNo
Word Count (Total)549
Word Count (Content)336
Links
External Links14
Internal Links23
Technical SEO
Meta NofollowNo
Meta NoarchiveNo
JS RenderedNo
Redirect Targetnull
Performance
Download Time (ms)1,564
TTFB (ms)1,564
Download Size (bytes)12,137
Shard43 (laksa)
Root Hash18237700010392947643
Unparsed URLorg,quickmathintuitions!/why-hash-tables-should-use-prime-number-size/ s443