President Reagan yesterday signed a bill to avert drastic cuts in railroad retirement benefits and save rail workers' pension funds from bankruptcy.

"None of us would pretend this bill is perfect," Reagan said at the Rose Garden signing ceremony. "It is a compromise . . . to assure the timely payment of rail pensions to 1 million rail retirees, the majority of whom are elderly."

Without remedial legislation, the railroad fund, crippled by a precipitous decline in the number of workers available to help support the system with payroll taxes, faced a $13-billion shortfall by 1992. Next year a cut of 40 percent in the portion of the benefit above a level equal to Social Security would have been mandatory, and further cuts were set for the following year.

As a start on bringing the retirement funds nearer to long-run solvency, the bill signed yesterday increases payroll taxes on employers and employes by about $1.8 billion over the next three years.

It also cuts benefits by $1.2 billion over the same period by delaying a cost-of-living increase for six months next year, providing for taxation of part of the monthly benefit and feeding the proceeds back to support the pension fund, reducing the benefits for future retirees who choose to stop work before age 62 and making certain other changes.

In addition, it authorizes $1.7 billion in federal payments to help cover special costs for past retirees who were eligible for both railroad and Social Security retirement benefits.

These changes are expected to carry the retirement fund to the end of the decade.

However, the railroad unemployment insurance fund also is in deep trouble and will remain in heavy debt to the retirement fund, despite an increase in the taxable wage base from $400 to $600 a month per employe.

The bill requires labor and management to work out a plan to clear the unemployment fund's debt to the retirement fund and submit the plan to Congress next year. Otherwise, a big new tax will be imposed for this purpose.

"The real test will come next year when a plan must be laid out to provide for solvency of the unemployment fund," said Rep. J.J. (Jake) Pickle (D-Tex.), who worked on the bill as chairman of the House Social Security subcommittee.

The main problem for the railroad retirement system is the decline in the number of workers as planes, trucks and cars claimed a big share of the transportation market and more efficient equipment was introduced.

In 1945 there were 1,680,000 rail workers, but by the end of the 1970s the figure had dropped to less than half that, and current estimates put it at 400,000.

That means there are 2 1/2 times as many retirees as active workers.

The retirement system has two tiers of benefits: Tier I, equivalent to Social Security, and Tier II, equal to the private pension that many workers elsewhere get in addition to Social Security. Under the bill, the Tier II tax rate for employers will rise from 11.75 percent to 14.75 percent in steps by Jan. 1, 1986; the rate for employes will rise from 2 percent to 4.25 percent over the same period.

Tier II benefits will be taxed as income and the proceeds fed back to support the system. Sick pay will be taxed. The Tier II cost-of-living increase will be postponed from July 1, 1984, to Jan. 1, 1985.