I was wondering if I fly my c172 in class E airspace, and Class B base was 5000 MSL. should I keep specific distance from Class B? or is it okay to go up to 4900 MSL but not reaching 5000 MSL?
You should remain at least 500 feet vertical separation from the Class B airspace, considering your direction of flight in accordance with FAR 91.159 (proper VFR cruising altitude) if you are more than 3000 feet AGL. Or 2-3 miles lateral separation from Class B airspace (no regulation, just common sense).
If the Class B floor base altitude of 5000 feet msl is at or less than 3000 feet AGL, you could legally fly up to just below the base of the Class B and therefore come dangerously close to other aircraft operating at 5000 feet msl within the Class B. This is too close for safety (considering allowable altimeter error, you could actually be at the same true altitude as an aircraft flying in the Class B).
Bottom line, in my opinion, you should always be at least 500 feet vertically or 2-3 miles laterally from Class B airspace.
This is what the Aeronautical Information Manual states regarding Class B:
(see the AIM):AIM 3-2-2
There is no minimum (as far as I know) to the distance you should keep when avoiding any type of airspace. However if you are not on top of your altimeter settings at low altitude 100 ft is within an aggressive but potential altimeter setting change and you may accidentally bust the airspace due to an improper local pressure setting.
Generally airspaces (like a class B surrounding a major airport) are made to keep you away from something at the center (major airport) so keeping you a bit further from the edge of the airspace is not really relevant as they are designed to keep you far enough away already.
On the other hand 4900 would be an off beat VFR cruising altitude considering § 91.159 – VFR cruising altitude or flight level.
Some anecdotal advice I heard around the hanger once: ATC is looking at much fancier screens than that iPad in your lap or that 430 on the panel, you should never skirt airspaces that closely no matter the gear you've got