When I think of German Romantic painting, seen at its most beautiful in the works of Caspar David Friedrich, I think of strong compositions, bold contrasts of light and darkness, and a luminous tone overall suggesting the term "visionary". When the works are finished, they are very finished indeed, the paint surface brought to an enamelled perfection.

When they are not finished, or when the paint has been somewhat worn away, you see how much preparatory work went into each composition. There is a very detailed and seemingly complete underdrawing, executed in pencil or in pen and ink. Everything has been planned carefully, down to, or up to, the edges of the clouds. The canvases have been prepared with a white ground, which accounts for some of the luminosity of the final effect. On this white ground the draughtsman has gone to work, outlining everything.

A friend and pupil of Friedrich's tells us that the artist never made sketches, cartoons or colour studies for his pictures, since he thought that the imagination always went cold when such aids were used. Friedrich did not begin a painting until it stood, lively, before his soul. Then he went to work on the underdrawing.

But this just goes to show how misleading authoritative eyewitness accounts can be, for there survive sketchbooks and drawings, including drawings squared up for enlargement in the traditional method. There are drawings on tracing paper. There are oil studies of thick blocks of ice, presumably made in Dresden from observation of the Elbe, which were used in the extraordinary painting of a ship crushed in an iceberg - a scene which Friedrich could never have seen, although he would have known at second hand accounts of polar exploration.

This majestic work, The Polar Sea (dating from 1823-4) features in an exhibition that has just moved from Berlin to Hamburg, where it hangs opposite one of Friedrich's grandest canvases, the depiction of the vast snow-capped mountain, The Watzmann. The iceberg painting shows nature rejecting man's intrusion - the ship having been destroyed by the immense force that has pushed the blocks of ice upwards into a striking pyramidal composition. The mountain, another pyramid, seems to lie beyond human intervention. The large canvas is quite without signs of human or other animal life.

Rather surprisingly, it turns out that Friedrich never saw the Watzmann, the great peak near Berchtesgaden, either. What is more, a rocky outcrop dominating the middle distance is taken from sketches made by Friedrich elsewhere, while the peak itself is copied from a study by one of Friedrich's pupils, who had died young. Other painters had begun to visit Berchtesgaden and sketch the scenery for themselves. Friedrich, by contrast, had a vision of how the great peak ought to look, and this is what he constructed on canvas.

The two great studies of the terror and majesty of nature were exhibited together in 1826. The Polar Sea, the earlier of them, never sold in Friedrich's lifetime, but it ended up in the collection of the Hamburg Kunsthalle. The Watzmann did sell, and eventually disappeared from view until in 1937 it was offered to the National Gallery in Berlin. The director of the gallery at the time, Eberhard Hanfstaengl, was an expert on Friedrich (who had fallen into some obscurity) and was avidly collecting his work for the nation.

This was the period in which German galleries were encouraged to strengthen their German holdings, and did this often by getting rid not only of "degenerate art" but also of acknowledged masterpieces from non-German schools. The effects of this policy are visible in Germany still.

The vendor of the painting, a certain Martin Brunn, was of Jewish origin: he was selling up in order to get his wife and children, and himself, out of the country. The gallery made an immense effort to secure this lost masterpiece by Friedrich. Brunn got his family out, and made his way to the United States. Within two years The Watzmann was put away in storage for safe keeping. It survived the war and eventually went back to Berlin, where it hung for years in the Romantic gallery in Charlottenburg.

Only when the old National Gallery, on Museum Island in reunified Berlin, was reopened in 2001, and a new catalogue was produced, which mentioned Martin Brunn's name in the provenance for The Watzmann, was a check made for the original owners. Albert Brunn, Martin's son, was now nearly 80. He remembered the painting well, for it had hung on its own in the "Berliner Zimmer" (double room) of his parents' Charlottenburg flat. In 2003 he went back to Berlin for the first time, to discuss restitution: for although his father had been paid, the circumstances of the sale were such as to constitute duress.

The current exhibition celebrates the agreement whereby Albert Brunn's family were recompensed for the painting, which was bought by DekaBank and returned, on long-term loan, to the old National Gallery in Berlin. The admirable catalogue, in German, explains all about the transaction, in addition to setting forth the latest evidence on Friedrich's painting methods, the context of the painting and Romantic discovery of Berchtesgaden, almost two centuries ago.