I am building a pergola. What size of beam will span 20 feet. There will be no load on the beam aside from the weight of the beam itself
For a beam that long deflection will control over strength. A 2x6 HF#2 would pass code with 0.6" sag in the middle if you are ok with that. Going with a 2x4 will result in a deflection of about 1-3/4" and it will want to roll over in the middle since there are no bracing members. If you go with cedar or pressure treated, it will be more.