In August 1980 Ronald Reagan kickstarted his first run for the White House with a speech at the annual fair of Philadelphia, a small town in Mississippi. It was an odd choice of location for such a high-profile event, just days after he had accepted his party's nomination as presidential candidate. A community of a few thousand people, Philadelphia is well off the beaten track. But as he spoke in front of an enthusiastic and all-white crowd, his purpose became clearer. He famously posed on stage in a rocking chair, Nancy on his knee, her shoes caked in Mississippi mud. Then he started addressing the crowd.

He was in favour of states' rights, he said, earning a lusty cheer. That sounds innocent enough as a political statement, but made in the deep south it had resonance. It was a euphemism, widely recognised at that time, for support of southern racial segregation and opposition to the meddling anti-racism of the federal government.

It would have been a controversial statement anywhere in the south. But to make it in Philadelphia's fairground was more than that. A little more than a mile away from where Reagan spoke was the mound of earth where 16 years previously three young civil rights activists had been found buried, each one with a single shot through the heart. The men had been investigating an African-American church that had been burned to the ground by the Ku Klux Klan. Their murders, later immortalised in the Hollywood film Mississippi Burning, provoked nationwide revulsion and helped to secure the passage of Lyndon Johnson's civil rights act and with it the dismantling of southern segregation.

Given the location, Reagan's clarion call for states' rights was a bold and deeply cynical move. As the liberal commentator Paul Krugman has put it: "Everyone got the message."

And the message stuck. It helped convert southern whites, the so-called Dixiecrats who had backed the Democratic party for decades, to defect to Reagan's cause, securing him victory in 1980 and completing the Republican stranglehold on the south that remains firm to this day. Mississippi has voted Republican in every presidential election since Reagan entered the White House. In 2004, John Kerry carried not a single southern state.

But now something is in the air. In March the unthinkable came to Philadelphia, in the form of a politician who has dubbed himself "a black man with a funny name" and who won the Democratic primary in Mississippi by a landslide: Barack Obama.

His victory in this quintessential corner of the deep south has brought back to the surface questions of race and allegiance that have to some degree been suppressed or reconciled over the years. For the 40% of the town's 7,000 residents who are black, it is evidence that change - so long in coming - is on its way. But it has put the white leadership of the local Republican party, as one party member told me, into a tailspin. "The combination of Obama's liberal record, his middle name, Hussein, and his blackness - those three things are enough to put an elderly southern conservative into a state of shock."

Tonight, on the 45th anniversary of Martin Luther King's famous "I have a dream" speech in front of the Lincoln Memorial, Obama will present America with his own dream speech. But as he does so, the racial divisions that he hopes to transcend remain unclear. How much has the country moved on from the dark days of segregation? Are towns like Philadelphia now free of their past?

Despite the ugly symbolism of the town's history, today it looks outwardly transformed. The Confederate flag still flies in the central square as part of the Mississippi banner, but those other hallmarks of segregation - the separate drinking fountains, hospital waiting rooms, "coloured" sections at the back of the bus - are, of course, long gone. The schools are technically, if not practically, integrated; black businesses have opened up in the central square; even the local country club opened its doors to black members five years ago.

Stan Dearman has observed the gradual sea-change with a semi-outsider's eye. He moved to the town in 1966, about 18 months after the murders, to take up editorship of the local paper, the Neshoba Democrat. "I was hoping that most of the turmoil in this community was behind us, but it was just starting. It was like a cancer in the whole community. It wouldn't go away no matter how much people wanted it to."

But over time, he's noticed the prevailing mood of the town grow less clannish, less insular. The conviction in January 2005 of Edgar Ray Killen, a local resident, on three counts of manslaughter - the first and only successful prosecution of a perpetrator of the 1964 killings - was a huge step forward in Dearman's view, though he says six or seven men are still out there "who need to be brought before the bar of justice".

But it is striking that though Dearman thinks change has come to Mississippi, he doesn't think it will translate into an Obama victory, not in Philadelphia, at least. "There's still a racial edge. People still see things in black and white - it's deeply ingrained. The mindset is: whites vote Republican, blacks Democrat."

It is a sign of how the tectonic plates of race in the south are shifting that while Dearman, who is white, is sceptical about the extent of political movement, many of the black residents of Philadelphia are fired up, to use an Obamaism. James Young, 53, was of the generation put through state-enforced integration of schools, and bears the emotional scars to prove it. He remembers white kids hurling the N-word at him. He also recalls lying on the floor of his living room, his father with a gun in his hand, when the Klan were, in his words, "on the move".

For years the black side of the tracks in Philadelphia, where he still lives, had a cloud over it that was part apathy, part despondency. "If a black man stood for president you would just say, 'No way, no way'." Now, as a pastor in the local black church, he is exhorting the congregation to get out and register to vote.

"The generation that wouldn't contemplate a black president is passing on, and that's good for everybody. If it's not now, it's just around the corner. We will no longer be denied," he says.

How important is that for African Americans in the south?

"It's a feeling you can't put into words. It's like we are no longer a subculture. Finally it's given us reason to think we are part of the overall scheme of things."

That newfound optimism is reflected in voting trends in Mississippi. Until this year, the average turnout for a Democratic primary there would be about 90,000. In March it was 500,000, three-quarters of whom were black. In 2004, George Bush took the state with 670,000 votes to his name - suggesting that a huge turnout of black voters in November would give Obama a big bounce in Mississippi, a state with the highest proportion of African-Americans in the US (39%). That would certainly scare the Republican elders even more than they are already.

But, of course, that still leaves the balance of power in the hands of the majority white voters. As Professor Marty Wiseman of Mississippi State University explains, race is no longer the number one issue for most white voters, but it remains an issue. "Any Democratic candidate who gets a big turnout of black voters is off to a very good start. It's just getting that other 20% that's difficult."

Philadelphia has changed; its ugly old ways are being shed. But this is evolution, not revolution, and some of the racial canker remains. Several people tell me that interracial relationships are no longer taboo. And then I meet Taneil Long. She is sitting in her nail salon in the central square, serving a black customer, the smell of varnish heavy in the air. In 2002, after she split up with the white father of her two daughters, she started dating a black man.

"I honestly thought this would be different - I mean, we're not in the 60s any more. But it really became a big issue for me," she says.

The first thing she noticed was that her white clientele thinned out, to be replaced by a customer base largely comprising black women. Then her landlady turned on her, saying there had been complaints in her white neighbourhood about her boyfriend. "I asked her was there a problem with the fact that he was black. She told me I had to get out." The father of her children recently told the girls he will never allow them to go out with black men.

Long is herself mixed-race - part white, part Vienamese (her white father served in the Vietnam war), giving her a natural affinity to the mixed race Obama. And yet she is uncertain about him. "You don't want a president with no connection to Christianity," she says.

But he is a Christian, I reply, to her surprise.

"Really? I'd heard he was a Muslim."

I'd been warned about this. Young had told me that in his pastoral work he found the Muslim question frequently popping up. But even so, it was a shock to find the false rumour, spread maliciously by Republican-leaning websites and gossipmongers, circulating so freely.

It comes up in my chat with Steve Wilkerson, the affable white owner of a clothing shop, Steve's, on the square. He has worked hard for the past few years, together with black residents such as Young, to heal Philadelphia's troubled race relations. Wilkerson says he has received emails with such titles as "Obama: the real story", dwelling scurrilously on his supposed Muslim faith. He says there is much apprehension abroad. "When you drive through white neighbourhoods I don't think you'll see many Obama signs or bumper stickers. People who vote for him will do it quietly. They don't know who he is, what his religion is. Is he the antichrist?"

Wilkerson himself is clearly conflicted. He knows Obama calls himself a Christian and says "that's good enough for me. I'm not a judge." But later in our conversation he admits that he too is troubled. "I'd like reassurance about who he is, who's backing him, just to be sure there's not an underlying current."

What is his worst fear?

"That he does turn out to be a Muslim after all."

And it comes up forcefully when I step in to Wilson's barber shop. Wilson is sitting looking slightly forlorn in the empty premises, clippings of hair scattered on the floor around his feet. "I don't have anything against a black man as president," he begins. "But Obama, he's not qualified. When you are president you represent everyone, not just your race. I've heard him talk about 'his people'."

He goes on: "And what about his religion, he can't just drop his religion."

What do you mean, I ask.

"He's a Muslim."

No, he's not. He's a Christian.

"Well, he should make it clear he stands by Christian values in America. That he doesn't hold those other values."

But he has made that clear.

"I don't think he's done that at all. He's just run from it. He should have nipped it in the bud and made clear he's a president for everybody."

But he's said that. What else can he do?

"Just because he's a Muslim, he should make it clear he doesn't believe in suicide bombing and killing."

The prevalence in my admittedly unscientific survey of downtown Philadelphia of the Obama = Muslim myth helps explain the ongoing furore over race preoccupying the two presidential campaigns. Obama first sounded the alarm in June, saying he was preparing himself for underhand Republican tactics that would try to spread jitters among voters. "They're going to try and make you afraid of me. He's young and inexperienced and he's got a funny name. And did I mention he's black?"

That comment sank without trace, but when Obama repeated last month that the Republicans were trying to play up the fact that "he doesn't look like all those other presidents on those dollar bills", the McCain camp grabbed the ball and ran with it. A McCain aide accused Obama of playing the race card, from the bottom of the deck.

Despite McCain's protestations that he is fighting an honest and race-blind campaign, Obama has good reason to be wary about the negative hits that are now coming at him from the rival camp. He knows all too well that the Swiftboat attacks that floored John Kerry, by calling into question his wartime record in Vietnam, were made by outrider groups that kept themselves scrupulously clean of Bush's fingerprints. There has been a creeping drift towards racial innuendo within McCain's increasingly venomous campaign. Attack ads run over the summer have shown Obama playing basketball - an overwhelmingly black sport in the US - and placed him in juxtaposition with Britney Spears and Paris Hilton in what some commentators have interpreted as a play on that old taboo on black men associating with sexualised white women. In one of his earliest ads, McCain referred to himself pointedly as "the American president Americans have been waiting for". That is an uncanny echo of the secret advice we now know was given to Hillary Clinton by her former chief strategist, Mark Penn, during the primary contest. In leaked memos, he urged her to portray Obama as someone whose "roots to basic American values and culture are at best limited".

The Obama campaign is fighting back against this insidious and underhand play on his race by stressing all this week that his is a "very American story" - neatly turning on its head the message of his assailants. But that device is in part a recognition on his part that there is a problem.

As the Democratic convention opened in Denver, opinion polls suggested that the clear lead he had held over McCain nationally for several weeks had all but slipped away, creating a palpable anxiety among Democratic supporters. They know that by August in their respective presidential election years - 1988 and 2004 - Michael Dukakis was 17 points ahead of George Bush Sr and John Kerry was four points ahead of George Bush Jr. And we know what happened to them.

A growing chorus can be heard among pundits and pontificators. Is Obama's inability to pull away decisively from McCain, even though everything seems to be going in his favour, something to do with race? As John Heilemann, New York magazine's sharp political observer, has said: "Call me crazy, but isn't it possible, just possible, that Obama's lead is being inhibited by the fact that he is, you know, black?"

Certainly, a closer look at the polls uncovers a stubbornly consistent racial divide. A recent Gallup poll had 91% of black voters backing Obama - indicating a nationwide trend in tune with Mississippi. Hispanics were keen on him too, with 68%. But non-Hispanic whites showed a clear preference for McCain, at 49% to Obama's 39%. When you factor in gender, the disparity is yet more glaring. White women came out evenly divided between the two candidates, but look at the findings for white men: McCain 55%, Obama 34%.

That may not matter so much in the south, where white voters have - ever since Reagan's Philadelphia speech - tended to vote sheeplike for the Republicans anyway. But it could matter a lot in several northern states such as Ohio, Michigan or Pennsylvania where the contest is likely to be tight and where there is a preponderance of white working-class voters struggling in the economically stricken rust belt.

That's the thing about many discussions of race in the US - they so easily overlook the north. The assumption is that the south was where the problem started with slavery and the civil war, while the north has always been a haven of enlightenment.

But it is the north that today hosts the most segregated cities in the US. The most recent census in 2000 shows that nine out of the 10 most segregated cities are northern, including New York, Chicago, and Cleveland and Cincinnati in the crucial electoral battleground of Ohio. "The northern system of segregation has never been about symbols of power on the streets - separate water fountains - but about segregated neighbourhoods and workplaces," says Kevin Boyle, a specialist in race and culture at Ohio State University. He reminds us that Obama struggled to gain support among white working-class communities in several northern states in the primary fight against Hillary Clinton, where issues of race and class are interwoven. In Ohio, almost one in five Democratic voters told exit pollsters that race had loomed large in their decision (Clinton won by 54% to 44%). "States like Ohio are so close that just a couple of percent of voters who decide not to vote for him on grounds of race could swing the result," Boyle says.

To see how the race factor is playing in these areas I fly 800 miles north from Philadelphia, to Livonia in Michigan. It was listed in the 2000 census as the whitest town in America. About 95% of its 100,000 residents are white and less than 1% black. The neighbouring town, Detroit, is more than 80% black - and the region as a whole sits at the top of the nation's segregation league table.

So how do the residents of America's whitest town feel about a possible Obama presidency? Could they see him winning? "I don't think he has a snowball's chance," says Glenn, sitting out on his front porch in one of Livonia's more affluent areas, reading the local paper. "Not just because he's black - though that's a very good start - but because he has no experience."

Livonia has acquired a reputation for racial tetchiness over the years. Plans to build two big shopping malls led to protests from some residents who feared they would attract "Detroiters" - a reference to the residents of Livonia's predominately black neighbour. A recent case, successfully prosecuted by federal authorities, fined a Livonia landlord more than $700,000 for refusing to rent apartments to black families. "If blacks come in here, we really don't have anything available for them," the landlord told his employees, a clue perhaps to how Livonia has managed to stay so white over the years.

A few doors down from Glenn, Eric is the only black resident in this part of town. He appears the perfect neighbour. His lawn is neatly trimmed, the brass on his gas lamp polished to mirror quality. About the only quibble one might have is that he has allowed his hostas to be nibbled by slugs.

That hasn't stopped the grumbling. A couple of neighbours bluntly refuse to acknowledge him when passing on the street. One resident asked him if he were running a childcare scheme when some of his children's cousins stayed over. Another called the town authorities to complain he had a service vehicle in his drive, when other neighbours had much bigger trucks in theirs. He shrugs off these vexations: "They don't hurt me or my family." As for Obama's chances, he says, "Some people wonder what I'm doing here, let alone a black president of the United States."

About a mile away from Eric's home is the blue-collar area of Roseland. It has the same detached houses and neatly trimmed lawns, except everything is scaled down. That's how it is in America: class as defined not by accent or breeding, but by square feet of real estate. It is in streets such as these that the economic downturn is really biting - rising food and petrol prices, job lay-offs, housing foreclosures. Jack, watering his plants in the front garden, says the hardship has to some extent led to a feeling of togetherness locally, even with his few black neighbours. But he goes on to say: "A black president - that's a tough sell. Obama could be all right now, but come November people might say, 'Not yet'."

And so to my final knock on a door. It is answered by Margaret, a grandmother who has a big sign in her window saying, "Beware the Dog", and a Stars and Stripes flying above the lintel. She grew up in Detroit but moved to Livonia as part of the white flight from the city in the 60s. She is proud of her Scottish parentage, and of her solid Democratic roots, but she is swift to tell me that Obama is not experienced enough for the White House. Not experienced enough. The phrase is starting to sound as widely used in Livonia as Muslim was in Philadelphia. Then she says: "There's a lot of people who don't want a black man in the White House."

It occurs to me that of all the people I have spoken to - both in Livonia and in Philadelphia, towns separated by 800 miles and a divergent history - it has always been the "other people" who won't vote for Obama. Not a single person has said they personally would balk at a black president.

When she says there are a lot of people who don't want a black man in 1600 Pennsylvania Avenue, does that include her?

Pause.

"Not really."

Does "not really" mean yes or no?

"I wouldn't want to see it in my lifetime."

A black presidency?

"I wouldn't like to see it, OK?"

She gives me a look of cold steel that announces the conversation is over.

Margaret's rare blast of honesty provides closure of a sort to this journey around race and the presidential campain. But it would be wrong to leave it on such a note. At the age of 81, she is, after all, a product of the past more than an indication of the future. Despite Obama's narrow lead, he has crucial advantages over his opponent. He is hugely more charismatic and inspiring than McCain and he has energised his following in a way that the Republicans can only dream about. He also benefits from a historically unpopular Bush presidency and a tanking economy. If an Obama victory is by no means certain, it is a very healthy possibility.

Let's return to Dearman, former editor of Philadelphia's local paper, who has lived through some of the country's most shameful moments, including Ronald Reagan's fairground speech, to see happier times. I ask him what he thinks the sight of Obama's two daughters, Malia and Sasha, playing on the White House lawn, would mean for America. "It will be a big, big thing," he says. "It would say that we, as a country, have arrived. There's a need for redemption, there always will be. An Obama presidency will provide some of that redemption."