Directors of the Federal National Mortgage Association voted yesterday to pay a quarterly dividend of 4 cents a share to holders of its common stock, despite two quarterly operating losses in 1981 to date.

Distribution of the dividend allows the giant federally chartered buyer of mortgages known as Fannie Mae to keep its 25-year record of quarterly payouts intact with a minimal outlay of cash. Fannie Mae has 59 million shares of stock outstanding, so a 4-cent dividend costs only $2.36 million, which can easily be covered out of retained earnings.

Squeezed by soaring interest rates, Fannie Mae lost $40.1 million in the first six months of this year. The nominal dividend, which will be paid Aug. 25 to shareholders of record Aug. 4, is down from 16 cents a share in the two previous quarters and 32 cents in the third quarter of last year.

The operating losses, the slashed dividends and the decline of Fannie Mae stock, down to $9 a share on the New York Stock Exchange from a yearly high of $16.50, all reflect the heavy buffeting the company has taken from the long seige of high interest rates.

Fannie Mae Chairman David O. Maxwell said the board's decision to pay a dividend "was based on its confidence that strategies and programs are in place to return Fannie Mae to profitability," an assessment greeted with some skepticism on Wall Street.

Fannie Mae's "strategies" consist of "a daily meeting to pray that interest rates go down," quipped Elliot Schneider, an analyst with Gruntal Co. He noted that Fannie Mae is a unique company in that the problems it faces are mostly beyond the control of its management, so "there isn't much they can do except at the margin."

Fannie Mae's basic difficulty is that its $58 billion mortgage portfolio is yielding an average return of 9.34 percent, while the organization is paying more than 15 percent for the vast borrowings it must make.