Here are the groups of priests the sons of Aaron were separated into. The sons of Aaron were Nadab, Abihu, Eleazar and Ithamar.
References for 1 Chronicles 24:1
But Nadab and Abihu died before their father did. They didn't have any sons. So Eleazar and Ithamar served as the priests.
With the help of Zadok and Ahimelech, David separated the priests into groups. Each group served in its appointed order and time. Zadok belonged to the family line of Eleazar. Ahimelech belonged to the family line of Ithamar.
More leaders were found among Eleazar's family line than among Ithamar's. So the priests were separated into their groups based on that fact. There were 16 family leaders from Eleazar's line. There were eight family leaders from Ithamar's line.
The priests were separated into their groups by using lots. That was the fair way to do it. The priests were officials of the temple and officials of God. They came from the family lines of Eleazar and Ithamar.
Shemaiah was a Levite. He was the son of Nethanel. He was the writer who recorded the names of the priests. He wrote them down in front of the king and the officials. The officials included the priest Zadok and Ahimelech. Ahimelech was the son of Abiathar. They also included the leaders of the families of the priests and the Levites. One family was chosen by lot from Eleazar. Then one was chosen from Ithamar.
The 1st lot that was drawn out was for Jehoiarib. The 2nd was for Jedaiah.
The 3rd was for Harim. The 4th was for Seorim.
The 5th was for Malkijah. The 6th was for Mijamin.
The 7th was for Hakkoz. The 8th was for Abijah.
The 9th was for Jeshua. The 10th was for Shecaniah.
The 11th was for Eliashib. The 12th was for Jakim.
The 13th was for Huppah. The 14th was for Jeshebeab.
The 15th was for Bilgah. The 16th was for Immer.
The 17th was for Hezir. The 18th was for Happizzez.
The 19th was for Pethahiah. The 20th was for Jehezkel.
The 21st was for Jakin. The 22nd was for Gamul.
The 23rd was for Delaiah. The 24th was for Maaziah.
That was their appointed order for serving when they entered the LORD's temple. That order was based on the rules Aaron had given them long ago. Everything was done exactly as the LORD had commanded Aaron. The LORD is the God of Israel.
Here are the other members of the family line of Levi. From the sons of Amram came Shubael. From the sons of Shubael came Jehdeiah.
References for 1 Chronicles 24:20
From the sons of Rehabiah came Isshiah. Isshiah was the oldest.
From the people of Izhar came Shelomoth. From the sons of Shelomoth came Jahath.
Jeriah was the first son of Hebron. Amariah was his second son. Jahaziel was the third. Jekameam was the fourth.
The son of Uzziel was Micah. From the sons of Micah came Shamir.
The brother of Micah was Isshiah. From the sons of Isshiah came Zechariah.
The sons of Merari were Mahli and Mushi. The son of Jaaziah was Beno.
The sons of Merari from Jaaziah were Beno, Shoham, Zaccur and Ibri.
From Mahli came Eleazar. Eleazar didn't have any sons.
From Kish came Jerahmeel. Jerahmeel was the son of Kish.
The sons of Mushi were Mahli, Eder and Jerimoth. Those were the Levites, family by family.
They cast lots, just as their relatives, the sons of Aaron, had done. They did it in front of King David, Zadok and Ahimelech. They did it in front of the family leaders of the priests. They also did it in front of the family leaders of the Levites. The families of the oldest brother were treated in the same way as the families of the youngest.