Two voltages
An Arduino Uno runs on 5 volts, so its HIGH is about 5 V. An ESP32 runs on 3.3 volts, so its HIGH is about 3.3 V. We want to wire a pin of one to a pin of the other, both ways.
An input reads HIGH above one voltage and LOW below another. The Uno needs 3 V for HIGH, 1.5 V or less for LOW. The ESP32 needs 2.48 V and 0.82 V. In between, nothing is promised.
Stepping down
Wire the Uno's TX straight to the ESP32's RX and a HIGH puts 5 V on it. The ESP32 datasheet allows at most 3.6 V on a pin. That is 1.4 V too much, and it can damage the chip.
Put two resistors in the way: 1 kΩ in series, then 2 kΩ down to ground. They share the 5 V in proportion, so the middle sits at 5 × 2 ÷ 3 = 3.33 V.
3.33 V is above the ESP32's 2.48 V, so it reads HIGH, and below 3.6 V, so the pin is safe. A LOW of 0 V stays 0 V. A divider only steps down, so line 2 needs something else.
Stepping up
Now the ESP32's TX drives the Uno's RX. 3.3 V cannot harm a 5 V pin. But the Uno needs 3 V for HIGH, and the ESP32 only promises 2.64 V. Often it works; it is not guaranteed.
Use one transistor, a BSS138 MOSFET. Its gate is tied to 3.3 V. Its source side has a 10 kΩ pull-up to 3.3 V, and its drain side a 10 kΩ pull-up to 5 V. Each side keeps its own voltage.
The ESP32 lets its side sit at 3.3 V. Gate and source are both at 3.3 V, a difference of 0 V, so the MOSFET stays off. The 10 kΩ pull-up lifts the Uno's side to a full 5 V: a clear HIGH.
Now the ESP32 pulls its side to 0 V. The gate is still at 3.3 V, so the difference is 3.3 V, well past the 1.5 V the MOSFET needs. It switches on and drags the Uno's side down to 0 V: LOW.
On a two-way bus such as I2C, either end may pull the line low. If the 5 V side pulls low, a diode built into the MOSFET drags the 3.3 V side down until the transistor turns on. One part shifts both ways.
What happens
;; step 1/10 · two-voltages Uno R3 ATmega328P, supply 5 V HIGH ≈ 5 V ESP32 supply 3.3 V HIGH ≈ 3.3 V LOW is about 0 V on both line 1 Uno TX -> ESP32 RX line 2 ESP32 TX -> Uno RX
Thresholds are datasheet guarantees, not exact switch points. ATmega328P (Table 30-1): LOW up to 0.3 × VCC, HIGH from 0.6 × VCC, for VCC from 2.4 V to 5.5 V. ESP32 (Table 5-3, at 3.3 V and 25 °C): LOW up to 0.25 × VDD, HIGH from 0.75 × VDD, and at most VDD + 0.3 V. The datasheets give 2.48 V as 2.475 V and 0.82 V as 0.825 V; the figure rounds them to the safe side. The BSS138's gate threshold is 0.8 V to 1.5 V (typically 1.3 V), so with its gate on 3.3 V it is surely off at 0 V and surely on at 3.3 V. The three cases are NXP's application note AN10441 on I2C level shifting. Ready-made boards put four of these, each with two 10 kΩ pull-ups, on one breakout.