The Provider must explore the binary trie formed by the DHT Servers Kademlia Identifiers, and find the longest Prefixes (trie node) that has at least 20 leaf children. These longest Prefixes cover the complete keyspace, but aren’t necessarily the same length.
If a Prefix node (trie node that isn’t a leaf) has at least 20 leaf children (20 peerids starting with this prefix), then the Provider Records starting with the Prefix will be allocated to the leaf children of the Prefix node.

What happens with the first Provide?
The first Provide operations happens “normally”. The node call FindClosestPeers for the given key, and allocate the Provider Record to the 20 closest peers.
How do we get the initial sweep going?
The initial sweep is starting after the first Provide Operation. This means that republishInterval after the first Provide Operation, the Prefix of the first Provider Record will be republished. From the initial Provide Operation, the reprovide sweep “left-to-right” will be ongoing for existing prefixes. This means that for example if there are only 2 provider records, first “00101” and second “00001”, “00101” is republished every republishInterval with a shift of origin and “00001” is republished every republishInterval with a shift of origin + republishInterval/2, with origin being the time of the first Provide.
What happens when new Provider Records are added?
When a new Provider Record is added, it is published “normally”, using the FindClosestPeers RPC. It is then republished along with the other Provider Records sharing the same prefix. This implies that the Provider Record will probably be republished before republishInterval.
What if the node is publishing less Provider Records than there are DHT Servers?
If a Provider Record is the only one to be reprovided on a set of 20 DHT Servers, then the operation is equivalent to a “normal” reprovide.
What happens when the networks grows/shrinks?
Network shrinking:
When the network shrinks we detect it because the Prefix we used to allocate a group of keys doesn’t have 20 children anymore. In this case we verify whether its parent has 20 leaf children, and go up the ancestors until we find one with at least 20 children. We then republish all the keys matching the ancestor’s Prefix at the same time. The republish time is the average between the planned republished time of the first and the last Prefixes inside the Ancestor subtrie. Note that the republishIntervalMax must be respected for all Provider Records.