John B. Anderson is a self-proclaimed long shot for the presidency, but the political discontent and uncertainties of 1980 are sufficient to give his prospective independent candidacy real hope of winning.

If history is the guide, Anderson does not have a prayer. No independent campaign has won a presidential election since the two major parties became dominant. But a new Washington Post survey of American voters, which shows Anderson getting 17 percent nationally and running third in a three-way race, suggests why the Illinois congressman can make the plunge and hope to upset history.

Anderson's readiness to run an independent campaign comes at a time when deep divisions appear to be growing among the rank and file of both parties. Anderson will be entering a race in which a great many Democrats are opposed to both President Carter and Edward Kennedy, the potential Democratic nominees, and in which a high proportion of Republicans are opposed to Ronald Reagan, the almost certain nominee of that party.

Anderson is not yet the beneficiary of that discontent, but he hopes to be by November.

Among Democrats, The Post's poll shows, support for Carter during this primary season is based largely on disapproval of Kennedy as the party's nominee, and not on approval of the president. Similarly, the majority of those who support Kennedy cite disapproval of Carter as the underlying reason for their decision.

Many of these Democrats appear ready to defect in a general election campaign. Almost half of those who back Kennedy over Carter say they are not prepared to vote for the president in a race against Reagan. More than half of those who support Carter over Kennedy fail to say they would vote for Kennedy if he were the nominee against Reagan.

In a three-way race, potential Democrat defection is even more sizable. Only 44 percent of the Kennedy supporters polled said they would vote for Carter in a three-way race between the president, Reagan and Anderson. Only 35 percent of Carter supporters said they would vote for Kennedy if he were the Democratic nominee in such a race.

Whether such massive defection would occur is questionable, of course. Primary election periods have long served as times in which voters register protest. The bulk of the Democratic rank and file could well fall back in line by November.

There is no assurance that Anderson would be greatly helped by continued divisiveness among Democrats. At this moment, according to The Post's Poll, Reagan picks up substantially more support for Democrats -- and from independents as well -- than does Anderson in three-way race.

Looked at from that view, Anderson's long-shot bid for the presidency could parallel that of George Wallace's in 1968: he could prove to be a spoiler. Wallace started out roughly equal to Anderson in the public opinion polls, but on Election Day he drew only 14 percent of the popular vote.

Wallace siphoned off more Democratic than Republican votes, allowing Richard M. Nixon to squeak by Hubert H. Humphrey by a margin of less than 1 percent of the vote nationwide.

But 1980 is not 1968. This time, in addition to unhappy Democrats, there appear to be a great many Republicans who are strongly opposed to their party's prospective nominee, Reagan. In proportions almost as large as the possible Democratic defectors, they say they are ready to vote for another candidate if Reagan gets the nomination.

The Post poll asked people who identified themselves as Republicans and independents whether they approved or disapproved of Reagan as the Republican nominee. Among Republicans, 66 percent said they approved and 27 percent said they disapproved. With independents included, 57 percent said they approved and 32 percent said they disapproved.

Seventy percent of the Republicans interviewed said they would vote for Reagan over Carter in a two-way race; 23 percent said they would vote for Carter and 7 percent said they were undecided. With Anderson entered as a third candidate, Reagan kept only 60 percent of the Republican support in the poll.

Anderson is not now the main beneficiary of this potential party defection, either. Carter stands to pick up somewhat more Republican votes than does the Illinois congressman.

But Anderson's strategy as an independent is based on the assumption that Carter and Reagan will be significantly weaker by Novemeber and that dissatisfied voters increasingly will turn to Anderson as the alternative.

Anderson says Reagan may not be able to stand up to close scrutiny over the next several months and that Carter's handling of the economy and foreign affairs could make him even more unpopular by the fall.

Public opinion polls have moved sharply this year in response to events, and Anderson could benefit from any changes.And while he begins well back in a three-way race, the 1980 campaign has already witnessed sharp fluctuations in candidate standings.

In addition, Anderson will target his campaign at independent voters. Of the 1,873 people interviewed in The Post's poll from April 9 to 13, 32 percent of all people who said they were registered to vote identified themselves as independents.

In a two-way race between Carter and Reagan, Carter leads among those independents by a slight 51-to-46 percent. With Anderson included, Carter and Reagan are tied at 38 percent and Anderson draws 22 percent of the independent vote.

Overall, The Post's poll shows that an Anderson candidacy would be more damaging now to Carter than to Reagan. This probably explains the present alarm in the Carter camp at the prospect of Anderson running.

(That alarm was apparent yesterday in the remarks of one of Carter's closest advisers, who told two reporters about his discovery that Anderson had sponsored a constitutional amendment in the 1960s that might prove embarrassing in the campaign.

(The amendment, which Anderson apparrently introduced several times between 1961 and 1965, would have added this language to the Constitution: "This nation devoutly recognizes the authority and law of Jesus Christ, Saviour and Ruler of nations, through whom are bestowed the blessing of Almighty God." Anderson has recently said that "I was totally wrong" to introduce this amendment, which he now disavows.)

According to the poll, Anderson is strongest right now among more affluent and better educated Americans. Among those who described themselves as professional people, for example, Anderson, Reagan and Carter drew almost equal support in a three-way race, with the president getting 34 percent and the other two 33 percent each. To win an election, he will clearly have to expand that base.

Among those who reported having family incomes of less than $8,000 a year, Anderson was supported by 8 percent in such a three-way race; among those with incomes of $30,000 or more he got 25 percent.

Anderson appears to face the most resistance in the South, where only 12 percent would support him against Carter and Reagan, and best in the West, where he drew 25 percet against them in the poll.