Absolutely risk-free investments do not exist, so the risk-free rate is taken as the return of an instrument with the lowest credit risk in a given currency and timeframe. Usually these are government securities: it is believed that the state can fulfill obligations in its own currency with the highest probability among all borrowers in the country.
The practical purpose of this indicator is to serve as a comparison base. The difference between the return of a corporate bond and the risk-free rate for the same period is called the credit spread and shows how much the market requires for taking on additional risk. If a corporate issue offers a premium of only a few dozen basis points, the question is not whether this is much or little in absolute terms, but whether the premium is proportionate to the difference in reliability.
An important condition for correct comparison is matching currency and timeframe. The return of local currency government bonds cannot be directly compared with foreign currency returns: the difference between them reflects not the quality of the issuer, but expectations about exchange rates and inflation.