Spain's Socialist government is facing growing left-wing pressure to honor its electoral commitments for a referendum on continued membership in NATO.

In the latest peace protest, about 100,000 marched in Madrid yesterday to demand withdrawal from NATO and an end to the facilities extended to the United States at four Spanish bases, including the Rota naval depot at the entrance to the Mediterranean.

The protest march was the biggest to date on the issue and political sources said the anti-NATO groundswell was causing serious concern among Cabinet members who are wary that the Communist Party could capitalize on the referendum issue.

Last year, when they were in opposition, the Socialists opposed Spain's entry into NATO, which was sponsored by the centrist administration. They campaigned for last fall's national elections pledging a referendum on withdrawal from NATO but, once in power, have refused to set a date for it.

On his return from a NATO foreign ministers' conference last week, Foreign Minister Fernando Moran said there would be no referendum this year or next "because of existing East-West tensions." But he added the government would stage a NATO vote within its four-year mandate, which runs out at the end of 1986.

Government foot-dragging on the issue has caused resentment among left-wingers. Fueling the leftists' anger has been this spring's endorsement by the Socialist-dominated parliament of a renewed Spanish-U.S. defense agreement, which extends the use of the bases for another five-year term.

Yesterday's march in Madrid was called by anti-NATO action groups and disarmament supporters, but the leaders of the minority Communist Party marched in its front ranks. Before the protest, a spokesman for the Socialists said the government party would not back the demonstration because its organizers were "financed by Moscow."

Despite the party's disapproval the march was also sponsored by the Socialists' youth organization and by the majority labor union that is closely linked to the party.

According to recent public opinion polls, an overwhelming majority of Spaniards are against NATO membership. While other peace movements in Western Europe focus on the deployment of nuclear missiles, the Spanish protest is specifically against alignment with NATO and against the U.S. base facilities.

Public opposition to NATO draws on the country's long-standing tradition of neutrality (Spain did not take part in either of this century's two world wars) and on a common objection that the alliance does not cover Madrid's defensive needs.

Spain's NATO critics argue that membership does not guarantee the security of the Spanish enclaves of Ceuta and Melilla on Morocco's Mediterranean coast. Further, they argue that NATO membership has, because of Britain's hold over Gibraltar, put Madrid in the position of being allied to a power that maintains a colony on Spanish territory.

A final key factor governing Spanish thinking on NATO is the continued delays blocking Madrid's bid to join the European Community.

While the uppermost hierarchy of the Spanish armed forces is understood to be favorable to NATO and senior generals have endorsed continued membership, it is less certain that this view is representative of the officer corps as a whole. A straw poll of officers conducted by the magazine Defensa last year revealed a 50-50 split on the advantages of alliance membership to Spain.

The Socialist government's policy at present appears to be to play for time and use the NATO issue to press for guarantees on the North African enclaves and for a breakthrough on the Gibraltar dispute. Spanish officials also privately link the government's approach to NATO to the success or failure of the European Community negotiations, although publicly they recognize that the two issues are separate.

In the meantime, the government has frozen negotiations on joining NATO's military command structure and has announced a far-reaching assessment of Spain's defense requirements. The military command freeze was one of the government's first acts when it took office last December and Foreign Minister Moran reiterated last week that the western allies understood Spain's position.

But left-wing pressure for a referendum is expected to grow. The respected Madrid daily El Pais, noting that the Cabinet faces a challenge, said: "The NATO referendum is an electoral pledge the government is obliged to carry out and, if it does not do so, it is obliged to explain why not."