user2306: Is there an address format for P2WPKH or P2WSH? If P2WPKH uses the same address format as P2PKH, how does a wallet know which one to use?

user21052: 
Is there an address format for P2WPKH or P2WSH?

No.  BIP142 would have provided an address format for these output scripts, but it is in "deferred" status and expected to remain that way.  Wallet developers are being encouraged to discuss a new address format on the bitcoin-dev mailing list, and it is my understanding that one proposal may be coming soon.
In the meantime, BIP70 supports paying to arbitrary outputs, so it can be used for the native segwit outputs, as can any other software that communicates using its own protocol (such as payment channel software like that being used for various Lightning Network implementations).

If P2WPKH uses the same address format as P2PKH, how does a wallet know which one to use?

Although the new address proposal will probably not use base58check like the current address formats for P2PKH and P2SH, the now-deferred proposal in BIP142 explains how this could easily be done by changing the first byte of the address (which is a version number):
"For P2WPKH address, the address version is 6 (0x06) for a main-network address or 3 (0x03) for a testnet address.
"For P2WSH address, the address version is 10 (0x0A) for a main-network address or 40 (0x28) for a testnet address."

user101498: Yes. The format used for encoding native version 0 SegWit scriptPubKeys (P2WPKH and P2WSH) is bech32, defined by bip-0173.
Unfortunately, at the time of writing, a weakness has been discovered regarding the usage of this encoding for the proposed version 1 SegWit scriptPubKeys (Taproot).
There are ongoing discussions for how to modify this encoding for version 1 and onward SegWit addresses.


If P2WPKH uses the same address format as P2PKH, how does a wallet know which one to use?

SegWit scriptPubKeys, as defined by bip-0141, are constructed differently than legacy P2PKH scriptPubKeys.
Based on the Script, a wallet knows what encoding to use.
To be explicit:

If the scriptPubKey is of the the form DUP HASH160 <pk hash> EQUALVERIFY CHECKSIG

Use base58-check encoding


Else if the scriptPubKey is of the the form <1-byte push> <2-to-40-bytes push>

Use bech32 encoding



It's likely that a new branch will be eventually be added to the above logic based on the new encoding that will be chosen for version >= 1 SegWit scriptPubKeys.

2306: <p>Is there an address format for P2WPKH or P2WSH? If P2WPKH uses the same address format as P2PKH, how does a wallet know which one to use?</p>
 21052: <blockquote>
  <p>Is there an address format for P2WPKH or P2WSH?</p>
</blockquote>

<p>No.  <a href="https://github.com/bitcoin/bips/blob/master/bip-0142.mediawiki" rel="nofollow noreferrer">BIP142</a> would have provided an address format for these output scripts, but it is in "deferred" status and expected to remain that way.  Wallet developers are being <a href="https://bitcoincore.org/en/2016/10/27/segwit-upgrade-guide/#bitcoin-software-developers" rel="nofollow noreferrer">encouraged</a> to discuss a new address format on the bitcoin-dev mailing list, and it is my understanding that one proposal may be coming soon.</p>

<p>In the meantime, <a href="https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki" rel="nofollow noreferrer">BIP70</a> supports paying to arbitrary outputs, so it can be used for the native segwit outputs, as can any other software that communicates using its own protocol (such as payment channel software like that being used for various Lightning Network implementations).</p>

<blockquote>
  <p>If P2WPKH uses the same address format as P2PKH, how does a wallet know which one to use?</p>
</blockquote>

<p>Although the new address proposal will probably not use base58check like the current address formats for P2PKH and P2SH, the now-deferred proposal in BIP142 explains how this could easily be done by changing the first byte of the address (which is a version number):</p>

<p>"For P2WPKH address, the address version is 6 (0x06) for a main-network address or 3 (0x03) for a testnet address.</p>

<p>"For P2WSH address, the address version is 10 (0x0A) for a main-network address or 40 (0x28) for a testnet address."</p>
 101498: <p>Yes. The format used for encoding native version 0 SegWit <code>scriptPubKey</code>s (<code>P2WPKH</code> and <code>P2WSH</code>) is <code>bech32</code>, defined by <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki" rel="nofollow noreferrer"><code>bip-0173</code></a>.</p>
<p>Unfortunately, at the time of writing, a weakness <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-November/017443.html" rel="nofollow noreferrer">has been discovered</a> regarding the usage of this encoding for the proposed version 1 SegWit <code>scriptPubKey</code>s (<a href="https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki" rel="nofollow noreferrer">Taproot</a>).<br />
There are <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2020-October/018236.html" rel="nofollow noreferrer">ongoing discussions</a> for how to modify this encoding for version 1 and onward SegWit addresses.</p>
<hr />
<blockquote>
<p>If P2WPKH uses the same address format as P2PKH, how does a wallet know which one to use?</p>
</blockquote>
<p>SegWit <code>scriptPubKey</code>s, as defined by <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="nofollow noreferrer"><code>bip-0141</code></a>, are <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#witness-program" rel="nofollow noreferrer">constructed differently</a> than legacy <code>P2PKH</code> <code>scriptPubKey</code>s.</p>
<p>Based on the Script, a wallet knows what encoding to use.<br />
To be explicit:</p>
<ul>
<li>If the <code>scriptPubKey</code> is of the the form <code>DUP HASH160 &lt;pk hash&gt; EQUALVERIFY CHECKSIG</code>
<ul>
<li>Use base58-check encoding</li>
</ul>
</li>
<li>Else if the <code>scriptPubKey</code> is of the the form <code>&lt;1-byte push&gt; &lt;2-to-40-bytes push&gt;</code>
<ul>
<li>Use bech32 encoding</li>
</ul>
</li>
</ul>
<p>It's likely that a new branch will be eventually be added to the above logic based on the new encoding that will be chosen for version <code>&gt;= 1</code> SegWit <code>scriptPubKey</code>s.</p>
