(في) is used to indicate the existence of an entity within a defined container.
The container can be spatial (box, house, neighborhood, country, solar system or even universe) temporal (second, hour, day, week or even a century) or imaginary (dream, idea, mind, science, category or even speech).
(ب) is used to indicate the cause of an effect (in the meaning of "by the use of", "by the effect of" or "by the assistance of").
EX:
في يدي فرشاة
In my hand a brush
بيدي اكتب
With my hand I write