# Node Discovery Protocol - Node Table entries

I am currently trying to understand the node discovery protocol in ethereum. I found a few docs, where one of it is: https://github.com/ethereum/devp2p/blob/master/discv4.md

It says, that the distance between node is determined the following way

distance(n₁, n₂) = keccak256(n₁) XOR keccak256(n₂)


where n is the node ID.

Next, the information about neighbors is stored in a routing table consisting of 'k-buckets'.

What I don't understand is the following sentence:

For each 0 ≤ i < 256, every node keeps a k-bucket for nodes of distance between 2^i and 2^(i+1) from itself.


Let's say we have n1 = 0x80 and n2 = 0xF0. To keep it simple, we don't hash but use just the id. So we get the following distance: d = 0x70. The MSB differs now. In which bucket do I store the information now?

You must understand that the distant it can be simple interpret as the different of bit. Let's say n1 = 0x80 which in bit is 1000 0000. So the distant for each ith is this routing table:

0th 1000 0000
1th 1000 000x
2th 1000 00xx
3th 1000 0xxx
...


With each row ith contain k peers which contain information about said peer such as their peer address, network address, ... But in the paper it is call k-buckets.

In your example n1 want to communicate with n2 then it will check its routing table and see that the distant is:

7th 1xxx xxxx


then it will send the message to the k-bucket which in this case just n2 so it will send it direct to n2.

• Thanks for the resources. So far I understand the Kademlia protocol and the table with the distances :) Thanks for illustrating it. You are saying, that in my example, the entry of n2 is in the 7th bucket. So where do we use the keccak function then? – Donut Mar 23 '19 at 17:17