g | x | w | all
Bytes Lang Time Link
010Japt241129T181130ZShaggy
011Uiua241128T181204Znoodle p
047Perl 5 p241127T181334ZKjetil S
034Python 3.8 prerelease241127T153829Zsquarero
027Haskell241127T185037Zcolossus
014x86_64 machine code241127T191131Zanatolyg
033Python241128T110600ZAlbert.L
013MathGolf241128T095000ZKevin Cr
00705AB1E241128T081132ZKevin Cr
037Python 2241127T225233ZLucenapo
007Vyxal241127T202227Zemanresu
027R241127T184834Zpajonk
026APL+WIN241127T174604ZGraham
015Charcoal241127T172641ZNeil
063Retina241127T171210ZNeil
044Google Sheets241127T151536Zdoubleun
029JavaScript ES11241127T153219ZArnauld

Japt, 10 bytes

Inspired by Kevin's MathGolf solution.

@<G²pX}a!²

Try it

@<G²pX}a!²     :Implicit input of integer U
@              :Function taking an integer X as argument
 <             :  U is less than
  G            :    16
   ²           :    Squared
    pX         :    Raised to the power of X
      }        :End function
       a       :Apply the following method to the non-negative integers,
               : returning the first result that returns true
               : when passed through that function
        !²     :Power of 2

Uiua, 11 bytes

⍜ₙ⌈2⌈ₙ256+1

Try it: Uiua pad

⌈ₙ256+1 -- The number of bits needed to represent the number is the logarithm with base 256 of 1 + the input, rounded up.

⍜ₙ⌈2 -- "under logarithm ceiling 2", so \$2^{\lceil log_2 n \rceil}\$ (where \$ \lceil x \rceil \$ means x rounded up), yielding the smallest power of 2 greater than n.

Perl 5 -p, 47 bytes

$_=$_>9e10?8:$_?1<<1+log(log()/log 256)/log 2:1

Try it online!

The 10 bytes of $_>9e10?8: could have been dropped if log had more floating point accuracy I think. And $_=$_>=1<<32?8:$_>65535?4:$_>255?2:1 is 36 bytes Try it online!

Inspired by the Python from @Lucenaposition: $_=[1,2,4,4]->[log($_|1)/log 256]||8 Try it online! 36 bytes.

Python 3.8 (pre-release),  59   47   38  34 bytes

-12 bytes by having 5 more minutes to codegolf.
-9 bytes by stealing Arnauld's idea.
-4 bytes from Arnauld.

f=lambda n,k=8:n>>k<1or 2*f(n,2*k)

Try it online!

Haskell, 32 29 27 bytes

f n=until(\b->n<256^b)(*2)1

Try it online!

EDIT: -3 bytes because I realized I could drop the -1 if I switched to using <

EDIT 2: -2 bytes thanks to @xnor's suggestion to use 256^b.

x86_64 machine code, 14 bytes

B0 FF                mov         al,0FFh  
48 0F BD C0          bsr         rax,rax  
0F BD C8             bsr         ecx,eax  
B0 40                mov         al,40h  
D2 C0                rol         al,cl  
C3                   ret  

To apply this, we can calculate y = log2(log2(x)), and then z = 2 ** y, with suitable offsets and rounding.

To ensure good behavior near 0, the code first ensures x ≥ 255 (I think greater than 3 should be enough; used 255 for safety).

Python, 33 bytes

f=lambda n:n<256or 8-6*f(n**.5)%8

Attempt This Online!

Returns True for 1.

How?

Same idea as @xnor's comment here. The tricky bit was fixing the fp issue cheaply.

MathGolf, 13 bytes

8421Γgæ♠▬k>~Þ

Try it online.

Explanation:

8421          # Push 8,4,2,1 separated to the stack
    Γ         # Wrap all four into a list: [8,4,2,1]
     g        # Filter this list by,
      æ       # using four character as inner code-block:
       ♠      #  Push 256
        ▬     #  Take 256 to the power the current value
         k    #  Push the input
          >   #  Check whether the 256 to the value is larger than the input
           ~  # After the filter: dump all remaining digits to the stack
            Þ # Only keep the last one
              # (after which the entire stack is output implicitly as result)

05AB1E, 7 bytes

₁вg.²îo

Try it online or verify all test cases.

Explanation:

₁в       # Convert the (implicit) input-integer to a base-256 list
  g      # Pop and push its length
   .²    # Take the logarithm_2 of that
     î   # Ceil it
      o  # Take 2 to the power that
         # (which is output implicitly as result)

Python 2, 37 bytes

lambda n:'12448888'[len(bin(n))-3>>3]

Try it online!

Outputs a string (if it is allowed).

Python 2, 45 bytes

lambda n:0x88884421>>((len(bin(n))-3)/8*4)&15

Try it online!

Outputs a number.

Vyxal, 7 bytes

₈τL∆l⌈E

Try it Online!

  L     # Length
 τ      # when converting to base
₈       # 256
        # (i.e. number of bytes required) 
      E # 2 to the power of
   ∆l   # log2 of that
     ⌈  # rounded up

R, 29 27 bytes

\(n,k=2^(3:6))k[n<2^k][1]/8

Attempt This Online!

The last test-case is too large for R.

APL+WIN, 26 bytes

Prompts for integer

¯1↑((2⍟1⌈⎕)≥0,2*3+⍳3)/2*⍳4

Try it online Thanks to Dyalog Classic!

Charcoal, 15 bytes

IX²L↨÷⊖L⍘N²¦⁸¦²

Try it online! Link is to verbose version of code. Explanation:

         N      Input as an integer
        ⍘       Converted to string base
          ²     Literal integer `2`
       L        Length
      ⊖         Decremented
     ÷          Integer divided by
            ⁸   Literal integer `8`
    ↨           Converted to base
              ² Literal integer `2`
   L            Take the length
  ²             Literal integer `2`
 X              Raised to that power
I               Cast to string
                Implicitly print

The first base conversion converts 0 to "0" while the second one converts it to []. This makes a difference when taking the length.

Retina, 63 bytes

$
¶$`¶256¶65536¶4294967296
N`¶.+
Lm`^(.+)¶(.+¶)*\1$
C`¶
T`34`48

Try it online! Link includes test cases. Unfortunately I had to use Retina 1 for this as Retina 0.8.2 uses 32-bit arithmetic for sorting. Explanation:

$
¶$`¶256¶65536¶4294967296

Append a copy of the input and 256, its square and squared square.

N`¶.+

Sort the copy among the powers.

Lm`^(.+)¶(.+¶)*\1$

Find where it ended up.

C`¶

Count how many squares were needed, plus one.

T`34`48

Translate into a number of bytes.

Google Sheets, 44 bytes

=ifs(A1<2^8,1,A1<2^16,2,A1<2^32,4,A1<2^64,8)

screenshot

Google Sheets uses IEEE 754 double-precision with a significand of 53 bits for pretty much everything, so cannot go all the way up to 64-bit unsigned.

The output format rules specified in the question are quite rigid. This alternative version outputs an array where the first true value marks the minimum bytes required by the unsigned integer (23 bytes):

=sort(A2<2^2^{3,4,5,6})

screenshot2

JavaScript (ES11), 29 bytes

Expects a BigInt.

f=(n,k=8n)=>n>>k?2*f(n,k+k):1

Try it online!