"the total number of pencils and erasers in each bag was the same."
number of pencil bags is the same as number of eraser bags
so that means get the common factor (same number to be divided) between 80 and 96
factors for 80 pencils 1 x 80 2 x 40 4 x 20 5 x 16 8 x 10
factors for 96 erasers 1 x 96 2 x 48 3 x 32 4 x 24 6 x 16 8 x 12
"into as many bags as possible with no remainder."
that means, we need to find the same highest number from factors of of 80 and 96 → 16
"How many pencils were there in each bag?"
16 bags of 5 pencils in each bag
answer is 5 pencils