This is the question that causes the most confusion. The answer depends on one thing only: whether the tenant lives in the flat themselves.
The tenant occupies the flat → under the Civil Code, the owner's consent is not required. The tenant may sublet part of the flat without the landlord's knowledge.
The tenant does not live in the flat → the landlord's consent is required, and both the request and consent must be in writing; if the landlord remains silent for one month, consent is deemed to have been given, unless subletting has been prohibited by agreement (§ 2275). Subletting without consent is a serious breach of the tenant's obligations (§ 2276), for which the landlord may terminate the lease.
Cooperative flat → this depends on the cooperative's articles of association. Sometimes the right to sublet is expressly included in the articles of association; in other cases, the consent of the statutory body is required. Always review the articles of association before entering into the agreement.
Notice period for a sublease: unlike a lease, a sublease can be terminated without stating a reason. The law does not specify a special notice period for the sublease of a flat, so agree this expressly in the agreement. In any event, the sublease ends no later than the lease (§ 2277 and § 2278 of the Civil Code).