"Bei Freunden" is the plural of "bei einem Freund", with the indefinite article. You use it when you're not defining these friends further; all that matters for what you're saying is that they're friends.
Ich habe in Berlin bei Freunden übernachtet.
"Bei den Freunden" is the plural of "bei dem Freund" (or "beim Freund"), with the definite article. You basically use it when you're talking about friends who were mentioned before or are well-known to the person you're talking to, or you're defining them further:
A: Ich habe in Berlin bei Freunden übernachtet.
B: Bei wem denn?
A: Bei den Freunden, mit denen ich vor zwei Jahren in China war.
Weißt du noch, wie wir letztes Jahr in Berlin waren? Ich war letzte Woche wieder da, und ich habe wieder bei den Freunden übernachtet.