The German constitution says
Article 8 (translated)
All Germans have the right to assemble, without notification or permission, peacefully and unarmed.
For assemblies in the open this may be restricted by law or based on a law.
This leads to the various states passing laws on protests in the open. ("Under open skies," that is not in an enclosed building. It seems the point is that an enclosed protest within a building or the like is less likely to turn into an uncontrolled riot, hence less legally restricted.) These restrictions must not generally ban demonstrations, but they can balance the right to protest against the rights of other people (e.g. motorists who want to get through). Notably, right now the size of demonstrations is limited in some states by Corona restrictions.
Generally speaking, a demonstration may be pre-planned or spontaneous. If it is pre-planned, it must be coordinated with the police. The organizers give an estimate of the participants and their planned location or route. The police makes their own estimate and compares that to the route. 10 people would be asked to stay on the sidewalk rather than blocking a major intersection, 10,000 people can spill onto the street. When the organizers disagree with restrictions placed by the police, they can go to the courts for an injunction.
The details include things like having trucks with a public address systems, building a speakers' platform, etc. When those are too extensive in relation to the number of protesters, the situation might shade into special use permits for public sidewalks. Two or three people can get permission for a booth on the street corner, but this will be more restrictive than a demonstration as to the time and place (and there is a fee).
When a spontaneous demonstration forms, the organizers should inform the police so that appropriate traffic control measures can be taken. This is a bit problematic, how do you determine the organizer of a spontaneous assembly? Will the contact persons be held to the responsibilities of the organizer of a pre-planned assembly if the assembly is held by the authorities to be not spontaneous after all?
The laws extend this right from all Germans to all people in Germany, but those only have their rights granted by law, rather than by the constitution (unless it is a state constitution, e.g. in Bavaria).