user133407: I was reading this while doing some research: https://github.com/achow101/wallet-fingerprinting/blob/main/fingerprints.md and had some questions:
What is the default nLocktime for a transaction in Bitcoin Core?
Was it ever changed because I remember it being zero at some point?

user13866: 
What is the default nLocktime for a transaction in Bitcoin Core?

Wallet source code
In version 23.0 the wallet\spend.c includes this
/**
 * Return a height-based locktime for new transactions (uses the height of the
 * current chain tip unless we are not synced with the current chain
 */
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uint256& block_hash, int block_height)
{
    uint32_t locktime;
    // Discourage fee sniping.
    //
    // For a large miner the value of the transactions in the best block and
    // the mempool can exceed the cost of deliberately attempting to mine two
    // blocks to orphan the current best block. By setting nLockTime such that
    // only the next block can include the transaction, we discourage this
    // practice as the height restricted and limited blocksize gives miners
    // considering fee sniping fewer options for pulling off this attack.
    //
    // A simple way to think about this is from the wallet's point of view we
    // always want the blockchain to move forward. By setting nLockTime this
    // way we're basically making the statement that we only want this
    // transaction to appear in the next block; we don't want to potentially
    // encourage reorgs by allowing transactions to appear at lower heights
    // than the next block in forks of the best chain.
    //
    // Of course, the subsidy is high enough, and transaction volume low
    // enough, that fee sniping isn't a problem yet, but by implementing a fix
    // now we ensure code won't be written that makes assumptions about
    // nLockTime that preclude a fix later.
    if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
        locktime = block_height;


So bitcoin core sets locktime to the current block height to discourage fee sniping.
Release Notes
Release notes for version 0.11 (updated Aug 2015) say

Wallet
#2340 811c71d Discourage fee sniping with nLockTime


When using RPCs
Locktime is zero when transaction is created manually using RPCs like createpsbt or createrawtransaction. Else a random nearest block height is used in bitcoin core. (Source: OP experimentation)

Documented meaning of Locktime
It may help to consider the meaning of Locktime
The Protocol Documentation says

The block number or timestamp at which this transaction is unlocked:





Value
Description




0
Not locked


< 500000000
Block number at which this transaction is unlocked


>= 500000000
UNIX timestamp at which this transaction isunlocked





If all TxIn inputs have final (0xffffffff) sequence numbers then
lock_time is irrelevant. Otherwise, the transaction may not be added
to a block until after lock_time (see NLockTime).

If we look at some transactions in block 654,915 we can see that most transactions have either no lock (0) or a block number ...
C> blockchain -file blk02300.dat -block 100
Transactions in block 00000000000000000002FC97B15D50E38CEB0C6A83DA4344CE836B01FC841EEA




No.
V
Type
Ins
Outs
Lock
Satoshi
Id




1
1
Segwit
1
3
0
743862941
36FD1CE479F30EF1CA1E44F7B2CF63D21C5CA8DBB04C1D5551A26735DB0266B8


2
1
Legacy
1
2
0
99992768
D889E605D3DD5986C89A66F446FEB228A7BCE58278C5F62EED579DB730148001


3
1
Segwit
3
1
0
7685144
268705614DCB68AED6A3750172F445EDCE6179D149BE769AF08D253B7A21F22D


4
2
Legacy
2
1
0
7907240
F3E237ED279F039DA0FAAAF5285362FAD18BADFA9E97455007F39D2C0D275112


5
2
Legacy
6
36
654900
5739473461
8F5B79B4CAC8EEF4525996E7B0B1B02DF83F9199816F27BA7FDD3E57C098D069


6
2
Segwit
1
1
0
1310690
819977BFF99145BCD38024FE0A3BC5B03A82A0A5FAA4A8A8073DB2D1893CC4D0


7
1
Segwit
1
3
0
1376557
378F17EB675E8998D9E1B4283E2AA3E8FB0213827296E6FAB54C8ED78C5E3777


8
1
Segwit
2
5
0
558656062
800C2349DF26295A3AFFBAD35CBB98D82A26AD7F69C8A6BF78ACFE4483414130


9
2
Legacy
1
2
0
9845471
119308B6C68AFB33D621202B704EB3D77867C7CDF7496FBDDB3176EA33481992


10
2
Legacy
1
2
0
9845471
618CD9BBE59448307C2941183A6AB7AD9DB1837B5139BDFC578108D5B710D980


11
1
Segwit
1
1
0
3469300
28AAF790C652C2B07F67FF4FD0E37997CC562B8DB92633DF5E8684399E15DACB


12
1
Legacy
1
1
0
375540
1EE38AFEB454980F694E654713D01188EBCC91BFC4213874CAA5376C0B37CD66


13
1
Legacy
1
1
0
223479
FE02E255EF4200A1D16C5DEBB442933C4A22EA544E55452B905D47EA99ED9675


14
1
Legacy
1
1
0
1127700
CB227B308DC46B4B312BAE6704D6D3B7E2FC8CE3CB7B17E26BB1DB9EE5BAEFB8


15
1
Segwit
1
1
0
877025
EA1871DC8D71A2C8B9224DC3937DF90324AFBD3D266EBBD27AC7A4FE2FB15F89


16
1
Segwit
1
2
0
40824845
2C0607F2B4FA6A15CABBEDABAFDA198CC4A98D18EA134963CAC08E26FF31C3E8


17
2
Legacy
1
2
654914
550200
24EBB2CB89EAE962E89939D48BD35D731791D1ABE8AC911FC8909BCEB299D9F9


18
2
Legacy
1
2
654914
134435250
A7E6E408D619DEF6E43D00B03ACFD247DE7268EB34E751D437BB03961954DFF6


19
2
Segwit
1
2
654862
463598
DAF9BF664D3C4CFEB1D625351922C51867EE1C2A648BBE5281D5505D7DE54ECF


20
1
Segwit
2
2
0
6316861
7FBD3F3079E0AA2404D28800329974F2D9C2D1115E3BE39DAD4898CFC123C8BC




I'd guess most wallets make the default 0 since my quick look at this block seemed to show about 90% with that value.

Footnote: If we assume general use of block height in locktime is consistent with the approach in Bitcoin core, we can probably use this to see how fee rate affected delays in getting a transaction mined. Transactions 17 and 18 above were mined quickly, transaction 19 probably had to wait 52 blocks? (8-9 hours?)

133407: <p>I was reading this while doing some research: <a href="https://github.com/achow101/wallet-fingerprinting/blob/main/fingerprints.md" rel="nofollow noreferrer">https://github.com/achow101/wallet-fingerprinting/blob/main/fingerprints.md</a> and had some questions:</p>
<p>What is the default nLocktime for a transaction in Bitcoin Core?</p>
<p>Was it ever changed because I remember it being zero at some point?</p>
 13866: <blockquote>
<p><strong>What is the default nLocktime for a transaction in Bitcoin Core?</strong></p>
</blockquote>
<h2>Wallet source code</h2>
<p>In version 23.0 the <code>wallet\spend.c</code> includes this</p>
<pre class="lang-c prettyprint-override"><code>/**
 * Return a height-based locktime for new transactions (uses the height of the
 * current chain tip unless we are not synced with the current chain
 */
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain&amp; chain, const uint256&amp; block_hash, int block_height)
{
    uint32_t locktime;
    // Discourage fee sniping.
    //
    // For a large miner the value of the transactions in the best block and
    // the mempool can exceed the cost of deliberately attempting to mine two
    // blocks to orphan the current best block. By setting nLockTime such that
    // only the next block can include the transaction, we discourage this
    // practice as the height restricted and limited blocksize gives miners
    // considering fee sniping fewer options for pulling off this attack.
    //
    // A simple way to think about this is from the wallet's point of view we
    // always want the blockchain to move forward. By setting nLockTime this
    // way we're basically making the statement that we only want this
    // transaction to appear in the next block; we don't want to potentially
    // encourage reorgs by allowing transactions to appear at lower heights
    // than the next block in forks of the best chain.
    //
    // Of course, the subsidy is high enough, and transaction volume low
    // enough, that fee sniping isn't a problem yet, but by implementing a fix
    // now we ensure code won't be written that makes assumptions about
    // nLockTime that preclude a fix later.
    if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
        locktime = block_height;

</code></pre>
<p>So bitcoin core sets locktime to the current block height to discourage fee sniping.</p>
<h2>Release Notes</h2>
<p><a href="https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.11.0.md" rel="nofollow noreferrer">Release notes for version 0.11</a> (updated Aug 2015) say</p>
<blockquote>
<p>Wallet</p>
<p>#2340 811c71d Discourage fee sniping with nLockTime</p>
</blockquote>
<hr />
<h2>When using RPCs</h2>
<p>Locktime is zero when transaction is created manually using RPCs like <code>createpsbt</code> or <code>createrawtransaction</code>. Else a random nearest block height is used in bitcoin core. (Source: OP experimentation)</p>
<hr />
<h2>Documented meaning of Locktime</h2>
<p>It may help to consider the meaning of Locktime</p>
<p>The <a href="https://en.bitcoin.it/wiki/Protocol_documentation#tx" rel="nofollow noreferrer">Protocol Documentation</a> says</p>
<blockquote>
<p>The block number or timestamp at which this transaction is unlocked:</p>
</blockquote>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>Not locked</td>
</tr>
<tr>
<td>&lt; 500000000</td>
<td>Block number at which this transaction is unlocked</td>
</tr>
<tr>
<td>&gt;= 500000000</td>
<td>UNIX timestamp at which this transaction isunlocked</td>
</tr>
</tbody>
</table>
</div>
<blockquote>
<p>If all TxIn inputs have final (0xffffffff) sequence numbers then
lock_time is irrelevant. Otherwise, the transaction may not be added
to a block until after lock_time (see NLockTime).</p>
</blockquote>
<p>If we look at some transactions in block 654,915 we can see that most transactions have either no lock (0) or a block number ...</p>
<p>C&gt; blockchain -file blk02300.dat -block 100</p>
<p>Transactions in block 00000000000000000002FC97B15D50E38CEB0C6A83DA4344CE836B01FC841EEA</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>No.</th>
<th>V</th>
<th>Type</th>
<th style="text-align: right;">Ins</th>
<th style="text-align: right;">Outs</th>
<th style="text-align: right;">Lock</th>
<th style="text-align: right;">Satoshi</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">743862941</td>
<td>36FD1CE479F30EF1CA1E44F7B2CF63D21C5CA8DBB04C1D5551A26735DB0266B8</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">99992768</td>
<td>D889E605D3DD5986C89A66F446FEB228A7BCE58278C5F62EED579DB730148001</td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">7685144</td>
<td>268705614DCB68AED6A3750172F445EDCE6179D149BE769AF08D253B7A21F22D</td>
</tr>
<tr>
<td>4</td>
<td>2</td>
<td>Legacy</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">7907240</td>
<td>F3E237ED279F039DA0FAAAF5285362FAD18BADFA9E97455007F39D2C0D275112</td>
</tr>
<tr>
<td>5</td>
<td>2</td>
<td>Legacy</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">36</td>
<td style="text-align: right;">654900</td>
<td style="text-align: right;">5739473461</td>
<td>8F5B79B4CAC8EEF4525996E7B0B1B02DF83F9199816F27BA7FDD3E57C098D069</td>
</tr>
<tr>
<td>6</td>
<td>2</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1310690</td>
<td>819977BFF99145BCD38024FE0A3BC5B03A82A0A5FAA4A8A8073DB2D1893CC4D0</td>
</tr>
<tr>
<td>7</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1376557</td>
<td>378F17EB675E8998D9E1B4283E2AA3E8FB0213827296E6FAB54C8ED78C5E3777</td>
</tr>
<tr>
<td>8</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">558656062</td>
<td>800C2349DF26295A3AFFBAD35CBB98D82A26AD7F69C8A6BF78ACFE4483414130</td>
</tr>
<tr>
<td>9</td>
<td>2</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">9845471</td>
<td>119308B6C68AFB33D621202B704EB3D77867C7CDF7496FBDDB3176EA33481992</td>
</tr>
<tr>
<td>10</td>
<td>2</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">9845471</td>
<td>618CD9BBE59448307C2941183A6AB7AD9DB1837B5139BDFC578108D5B710D980</td>
</tr>
<tr>
<td>11</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3469300</td>
<td>28AAF790C652C2B07F67FF4FD0E37997CC562B8DB92633DF5E8684399E15DACB</td>
</tr>
<tr>
<td>12</td>
<td>1</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">375540</td>
<td>1EE38AFEB454980F694E654713D01188EBCC91BFC4213874CAA5376C0B37CD66</td>
</tr>
<tr>
<td>13</td>
<td>1</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">223479</td>
<td>FE02E255EF4200A1D16C5DEBB442933C4A22EA544E55452B905D47EA99ED9675</td>
</tr>
<tr>
<td>14</td>
<td>1</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1127700</td>
<td>CB227B308DC46B4B312BAE6704D6D3B7E2FC8CE3CB7B17E26BB1DB9EE5BAEFB8</td>
</tr>
<tr>
<td>15</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">877025</td>
<td>EA1871DC8D71A2C8B9224DC3937DF90324AFBD3D266EBBD27AC7A4FE2FB15F89</td>
</tr>
<tr>
<td>16</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">40824845</td>
<td>2C0607F2B4FA6A15CABBEDABAFDA198CC4A98D18EA134963CAC08E26FF31C3E8</td>
</tr>
<tr>
<td>17</td>
<td>2</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">654914</td>
<td style="text-align: right;">550200</td>
<td>24EBB2CB89EAE962E89939D48BD35D731791D1ABE8AC911FC8909BCEB299D9F9</td>
</tr>
<tr>
<td>18</td>
<td>2</td>
<td>Legacy</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">654914</td>
<td style="text-align: right;">134435250</td>
<td>A7E6E408D619DEF6E43D00B03ACFD247DE7268EB34E751D437BB03961954DFF6</td>
</tr>
<tr>
<td>19</td>
<td>2</td>
<td>Segwit</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">654862</td>
<td style="text-align: right;">463598</td>
<td>DAF9BF664D3C4CFEB1D625351922C51867EE1C2A648BBE5281D5505D7DE54ECF</td>
</tr>
<tr>
<td>20</td>
<td>1</td>
<td>Segwit</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">6316861</td>
<td>7FBD3F3079E0AA2404D28800329974F2D9C2D1115E3BE39DAD4898CFC123C8BC</td>
</tr>
</tbody>
</table>
</div>
<p>I'd guess most wallets make the default 0 since my quick look at this block seemed to show about 90% with that value.</p>
<hr />
<p>Footnote: If we assume general use of block height in locktime is consistent with the approach in Bitcoin core, we can probably use this to see how fee rate affected delays in getting a transaction mined. Transactions 17 and 18 above were mined quickly, transaction 19 probably had to wait 52 blocks? (8-9 hours?)</p>
