  Fault-tolerant quantum error correction (QEC) is crucial for unlocking the
true power of quantum computers. QEC codes use multiple physical qubits to
encode a logical qubit, which is protected against errors at the physical qubit
level. Here we use a trapped ion system to experimentally prepare $m$-qubit GHZ
states and sample the measurement results to construct $m\times m$ logical
states of the $[[m^2,1,m]]$ Shor code, up to $m=7$. The synthetic logical
fidelity shows how deeper encoding can compensate for additional gate errors in
state preparation for larger logical states. However, the optimal code size
depends on the physical error rate and we find that $m=5$ has the best
performance in our system. We further realize the direct logical encoding of
the $[[9,1,3]]$ Shor code on nine qubits in a thirteen-ion chain for
comparison, with $98.8(1)\%$ and $98.5(1)\%$ fidelity for state
$\left\vert\pm\right\rangle_L$, respectively.
